Program to find the largest of three numbers using if else

Write a program to find the largest of three numbers using if-else.

C Program

#include <stdio.h>
int main()
{
    int firstNumsecondNumthirdNum;

    printf("Enter first number : ");
    scanf("%d", &firstNum);

    printf("Enter second number : ");
    scanf("%d", &secondNum);

    printf("Enter third number : ");
    scanf("%d", &thirdNum);

    if (firstNum >= secondNum)
    {
        if (firstNum >= thirdNum)
        {
            printf("First is greater ");
        }
        else
        {
            printf("Third is greater ");
        }
    }
    else
    {
        if (secondNum >= thirdNum)
        {
            printf("Second is greater ");
        }
        else
        {
            printf("Third is greater ");
        }
    }
    return 0;
}

Example:

Enter first number : 20
Enter second number : 10
Enter third number : 15

Example:

First is greater 


No comments:

Post a Comment