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:




Comments

Popular posts from this blog

ATM solution in C language.- Codechef

MOTIVATION SOLUTION IN C LANGUAGE | CODECHEF | IMDB

APPLE AND ORANGE | HACKERRANK | PROBLEM SOLVING | SOLUTION IN C