(C Programming) Display the largest number and also the smallest number among the 3 numbers. Can anyone help? Thanks. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

(C Programming) Display the largest number and also the smallest number among the 3 numbers. Can anyone help? Thanks.

Our instructor wants us to use the if statements of C Programming, how may I able to do this if there are 3 numbers? Some says it is easy but I couldn't find it easy at my current timeline, I have tried 2 numbers only and it worked. Here's the code... #include <stdio.h> int main() { int a, b ; printf ("Enter the 2 numbers:\n"); scanf ("%d %d", &a, &b); if(a>b) { printf ("%d = a is the greatest number\n", a); printf ("%d = b is the least number\n", b); } if(a<b) { printf ("%d = b is the greatest number\n", b); printf ("%d = a is the least number\n", a); } return 0; }

31st Jul 2019, 11:34 PM
Kn47
Kn47 - avatar
2 Answers
0
You should create two new variables called min and max, the code should be similar to this: int a, b, c, min, max; a=0; b=0; c=0; min=0; max=0; printf... scanf... if(a>b) { max=a; min=b; } else{ max=b; min=a; } if(c>max) { max=c; } if(c<min) { min=c; } Then you print out the variable max and the variable min. Hope it's all clear now!
1st Aug 2019, 6:20 AM
Davide Mornatta
Davide Mornatta - avatar
0
I will try this bro, thankss!
3rd Aug 2019, 3:11 AM
Kn47
Kn47 - avatar