1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
pentagon [3]
2 years ago
6

New and just need help with C coding. I've tried if statements and it outputs the wrong number.

Computers and Technology
2 answers:
dimaraw [331]2 years ago
7 0

Answer:

#include <stdio.h>

int main(void) {

 

 int num1;

 int num2;

 int num3;

 printf("Enter three integers: ");

 scanf("%d", &num1);

 scanf("%d", &num2);

 scanf("%d", &num3);

 if (num1 == 0 || num2 == 0 || num3 == 0)

 {

   printf("please input a number greater than zero :)\n");

 }

 if (num1 <= num2 && num1 <= num3)

 {

   printf("%i is the smallest number!\n", num1);

 }

 else if (num2 <= num1 && num2 <= num3)

 {

   printf("%i is the smallest number!\n", num2);

 }

 else

 {

   printf("%i is the smallest number!\n", num3);

 }

 return 0;

}

Explanation:

Alright so let's start with the requirements of the question:

  1. must take 3 integers from user input
  2. determine which of these 3 numbers are the smallest
  3. spit out the number to out

So we needed to create 3 variables to hold each integer that was going to be passed into our script.

By using scanf("%i", &variableName) we were able to take in user input and  store it inside of num1, num2, and num3.

Since you mentioned you were new to the C programming language, I threw in the first if statement as an example of how they can be used, use it as a guide for future reference, sometimes it's better to understand your code visually.

Basically what this if statement does is, it checks to see if any of the integers that came in from user input was the number zero, it told the user it does not accept that number, please input a number greater than zero.

if (num1 == 0 || num2 == 0 || num3 == 0)

 {

   printf("please input a number greater than zero :)\n");

 }

I used this methodology and implemented the heart of the question,

whichever number is smaller, print it out on the shell (output).

if (num1 <= num2 && num1 <= num3)

^^ here we're checking if the first variable we created is smaller than the second variable and the third ^^

 {

   printf("%i is the smallest number!\n", num1);

   ^^ if it is smaller, then print integer and then print a new line so the next line looks neat ^^

   ( incase if your wondering what "\n" is, its a special character that allows you so print a new line on the terminal, kind of like hitting the return or enter key )

 }

else if (num2 <= num1 && num2 <= num3)

^^ else if is used when your checking for more than one thing, and so for the second variable we checked to see if it was smaller than the first and third variable we created ^^

 {

   printf("%i is the smallest number!\n", num2); < -- and we print if it's smaller

 }

Last but not least:

else

^^ if it isn't num1 or num2, then it must be num3 ^^

 {

   printf("%i is the smallest number!\n", num3);

  we checked the first two options, if its neither of those then we have only one variable left, and thats num3.

 }

I hope that helps !!

Good luck on your coding journey :) ‍

Zepler [3.9K]2 years ago
5 0

The Answer is in Bold: c++ language  

#include <iostream>

using namespace std;

int main() {

    int  a, b, c;      

cin >> a;        

cin >> b;

cin >> c;

  if (a < b && a < c)   {            

   cout << a <<endl;              

 }                                                    

else if(b < a && b < c)   {      

    cout << b << endl;

 }

 else   {

    cout << c <<endl;

}    

 return 0;

}

You might be interested in
Which osi layer defines the functions of logical network-wide addressing and routing?
IRISSAK [1]
Answer: The Network Layer
5 0
3 years ago
Hexadecimal to denary gcse method
Anuta_ua [19.1K]

There are two ways to convert from hexadecimal to denary gcse method. They are:

  • Conversion from hex to denary via binary.
  • The use of base 16 place-value columns.

<h3>How is the conversion done?</h3>

In Conversion from hex to denary via binary:

One has to Separate the hex digits to be able to know or find its equivalent in binary, and then the person will then put them back together.

Example - Find out the denary value of hex value 2D.

It will be:

2 = 0010

D = 1101

Put them them together and then you will have:

00101101

Which is known to be:

0 *128 + 0 * 64 + 1 *32 + 0 * 16 + 1 *8 + 1 *4 + 0 *2 + 1 *1

= 45 in denary form.

Learn more about hexadecimal from

brainly.com/question/11109762

#SPJ1

3 0
2 years ago
What are the specifications of mine shaft head gear​
svetlana [45]

Answer:

the depth of the shaft,

the carrying load of the skip and the mass of the counterweight,

the approximate size of the winding drum,

the approximate height of the headgear and the sheave wheel

4 0
2 years ago
Read 2 more answers
Question 1
weeeeeb [17]

Answer:

-6.4

Explanation:

just divide -32 by 5 and you will get your answer of -6.4

7 0
3 years ago
The operating systems, and utility programs that perform system
Phantasy [73]

Answer:

System softwares.

Explanation:

A software can be defined as a set of executable instructions (codes) or collection of data that is used typically to instruct a computer how to perform a specific task and to solve a particular problem.

Basically, softwares are categorized into two (2) main categories and these are;

I. Utility software.

II. System software.

The operating systems, and utility programs that perform system maintenance and protection tasks such as error correction and backup are called system softwares.

An operating system is a system software pre-installed on a computing device to manage or control software application, computer hardware and user processes.

This ultimately implies that, an operating system acts as an interface or intermediary between the computer end user and the hardware portion of the computer system (computer hardware) in the processing and execution of instructions.

Some examples of an operating system on computers are QNX, Linux, OpenVMS, MacOS, Microsoft windows, IBM, Solaris, VM etc.

On the other hand, a utility software can be defined as a software application or program designed to add more functionality to a computer system, as well as to improve its performance efficiently. Some examples of commonly used utility tools in computer are file and folder backup tools, file management, antivirus, hard disk diagnostics, registry cleaner, network performance monitor, screensavers etc.

4 0
2 years ago
Other questions:
  • How do the search methods differ for primary and secondary data?
    10·2 answers
  • Brian wants to conduct an online search using a certain phrase he intends to use the word books that belong to the 1800's in his
    8·1 answer
  • Discuss what they need to consider if they wish to use their devices when they are away from home?
    6·1 answer
  • How to send an email
    7·2 answers
  • I forgot to tell it’s on Roblox for those who play and wanted to be friends and new ppl username is mosarider489
    9·2 answers
  • "The _____ of the Open Systems Interconnection (OSI) model generates the receiver’s address and ensures the integrity of message
    6·2 answers
  • How can software be used to protect against hardware failures in systems that embody both? Give two examples of how software can
    14·1 answer
  • Monitors display images by using a grid made up of millions of tiny dots, called ________.
    13·1 answer
  • Search engines enable you to
    12·1 answer
  • Partes de la ventana principal de Microsoft excel 2013 con sus respectivas funciones
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!