C Program to check greater of three numbers.(using if-else)
C Program to check greater of three numbers.
(Entered by User)
#include <stdio.h>
int main() {
double a, b, c;
printf("Enter three numbers: ");
scanf("%lf %lf %lf", &a, &b, &c);
// checks if a is greater than b and c
if (a >= b && a >= c)
printf("%.2lf is the largest number.", a);
// checks if b is greater than a and c
else if (b >= a && b >= c)
printf("%.2lf is the largest number.", b);
// checks if c is greater than a and b
else
printf("%.2lf is largest of three number.", c);
return 0;
}
OUTPUT
Enter three numbers: 8 9.9 -5 9.90 is largest of three number.
EXPLANATION
- In above program (a >= b && a >= c) checks if a is greater than b and c if if condition satisfies above condition then printf function returns value a as the maximum value of three numbers.
- Similarly if (b >= a && b >= c) checks if b is greater than a and c if else if condition satisfies above condition then printf function returns value b as the maximum value of three numbers.
- If above two conditions does not satisfy then else statement get executed.
IF YOU HAVEN'T GO THROUGH PREVIOUS PROGRAMMING BLOGS:
- HELLO, WORLD! : https://bit.ly/3b8gNeB
- ADDING TWO INTEGERS : https://bit.ly/3gLvpBE
- PRINTING INTEGER, ITS SQUARE AND CUBE : https://bit.ly/2YOld5h
- ODD/EVEN : https://bit.ly/3lzTf6X
- CREATING CALCULATOR :https://bit.ly/3b9h9S4 >
Comments
Post a Comment