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]
3 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]3 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]3 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 of the following binary numbers is equivalent to decimal 4?
melomori [17]

Answer:

b so easy

Explanation:

5 0
3 years ago
Read 2 more answers
In Python, what kind of error is returned by the following code? (e.g. NameError, ValueError, IOError, etc.) def my_func(n1, n2)
kodGreya [7K]

Answer:

SyntaxError.

Explanation:

https://www.quora.com/In-Python-what-kind-of-error-is-returned-by-the-following-code-e-g-NameError-ValueError-IOError-etc-def-my_func-n1-n2-return-n1-n2-my_func-1-2-3          sorce site

<h2></h2><h2></h2><h2></h2><h2>brainlest plz</h2>
6 0
4 years ago
Evaluate the expression. Be sure to list a value of appropriate type (e.g., 7.0 rather than 7 for a double, Strings in quotes).
Mashutka [201]
<h2>Answer:</h2>

14.0

<h2>Explanation:</h2>

Using the level of precedence in Java,

From left to right;

(i) the first division operation will be done.

(ii)followed by the second division operation.

(iii)followed by the first multiplication operation.

(iv)followed by the third division operation.

(v)followed by the second multiplication operation.

(vi) followed by the first addition operation.

(vii)lastly followed by the second addition operation.

=================================================

Taking the steps above one after the other;

<em>(i) the first division operation will be done (i.e 19 / 2)</em>

=> Integer division in Java gives an integer result. Therefore, 19 / 2 = 9.5 will give 9.

So,

=><em> </em><u>19 / 2</u> / 2.0 + 2.5 * 6 / 2 + 0.5 * 4

=> 9 / 2.0 + 2.5 * 6 / 2 + 0.5 * 4

<em>(ii)followed by the second division operation. (i.e 9 / 2.0)</em>

=> From the result from step (i), the second division operation is now 9 / 2.0.

=> 9 / 2.0 = 4.5

So,

=> <u>9 / 2.0</u> + 2.5 * 6 / 2 + 0.5 * 4

=> 4.5 + 2.5 * 6 / 2 + 0.5 * 4

<em>(iii)followed by the first multiplication operation. (i.e 2.5 * 6)</em>

=> The first multiplication operation is given by 2.5 * 6

=> 2.5 * 6 = 15.0

So,

=> 4.5 + <u>2.5 * 6</u> / 2 + 0.5 * 4

=> 4.5 + 15.0 / 2 + 0.5 * 4

<em>(iv)followed by the third division operation. (i.e 15.0 / 2)</em>

=> The third division operation is given by 15.0 / 2

=> 15.0 / 2 = 7.5

So,

=> 4.5 + <u>15.0 / 2</u> + 0.5 * 4

=> 4.5 + 7.5 + 0.5 * 4

<em>(v)followed by the second multiplication operation. (i.e 0.5 * 4)</em>

=> The second multiplication operation is given by 0.5 * 4

=> 0.5 * 4 = 2.0

So,

=> 4.5 + 7.5 + <u>0.5 * 4</u>

=> 4.5 + 7.5 + 2.0

<em>(vi) followed by the first addition operation. (i.e 4.5 + 7.5)</em>

=> The first addition operation is given by 4.5 + 7.5

=> 4.5 + 7.5 = 12.0

So,

=> <u>4.5 + 7.5</u> + 2.0

=> 12.0 + 2.0

<em>(vii) lastly followed by the second addition operation. (i.e 12.0 + 2.0)</em>

=> The second addition operation is given by 12.0 + 2.0

=> 12.0 + 2.0 = 14.0

So,

=> <u>12.0 + 2.0</u>

=> 14.0

<em>Therefore, 19 / 2 / 2.0 + 2.5 * 6 / 2 + 0.5 * 4 = 14.0</em>

<h2>Note:</h2>

In Java, the order of precedence for arithmetic operators is;

=> /, * and %

=> followed by + and -

6 0
3 years ago
A user could find the icon for an attached usb flash drive under what heading in the my computer/computer window?
xxMikexx [17]
  <span>Hi... 

There are three answers ..... 

If the flash drive has a custom icon then there is hidden files on the flash drive. 
An autorun.inf file and a small .ico image file ..... 
( Click organize > Folder and search options >View>Show hidden folders and files. ) 


If the flash drive displays a windows created icon the source directory's are.. 
%SystemRoot%\system32\SHELL32.dll 
%SystemRoot%\system32\imageres.dll 





If the Flash drive has a custom icon stored on the computer the "original source file " could be any ware. 
The image preference retained in AppData.. 

Select flash drive >Right click>Properties>Customize , i take a good ICT course, can u make this the brainliest?</span>
7 0
4 years ago
Combustion is an example of to energy conversion.
Marizza181 [45]
If this is a true or false question I would say true... but I dont know I’m confusion <3
7 0
3 years ago
Other questions:
  • Chances are if you ar Chances are, if you are involved in a crash, it will happen __________ a. during a long trip. b. close to
    7·2 answers
  • ____________ facilitates the processes that help an organization function by applying information and communication technologies
    5·1 answer
  • According to what theory did the universe expand explosively into existence 13.7 billion years ago?
    13·2 answers
  • What layout manager should you use so that every component occupies the same size in the container?
    5·1 answer
  • A program is
    7·1 answer
  • You're expecting visitors who will be demanding Mamet access Before they arrive, you can activate a Guest network that has its o
    11·1 answer
  • Explain any two features of a computer​
    15·1 answer
  • Write a code segment that will store a dinner selection in option1 based on the values of rsvp and selection. The intended behav
    5·1 answer
  • 9. How much is gaming and video game streaming predicted to grow from 2018-2026?
    14·1 answer
  • write a function print array to print an array on one line as: 9 8 7 6 5 4 3 2 1 0 write and test a function called bubble sort
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!