Largest number among to three number in c

Largest number among to three number in c

C program to Find the Largest Number Among Three Numbers

To find the largest number among three numbers, we compare them using basic conditional statements or logical operators. Here's a clear description:

Input:

Enter three number (Let these numbers be num1, num2, and num3).

Comparison:

First, compare num1 with num2 and num3.
If num1 is greater than or equal to both, it's the largest.
Otherwise, compare num2 with num3.
If num2 is greater than or equal to num3, it's the largest.
Otherwise, num3 is the largest.
By this process we can find the largest number out of three numbers

Code:

//In this program we will find the 
//largest number to among three numbers.
// using if-else 
#include <stdio.h>
int main()
{
    // input three numbers
    float num1, num2, num3;
    
    printf("Enter 1st number: ");
    scanf("%f", &num1);
    
    printf("Enter 2nd number: ");
    scanf("%f", &num2);
    
    printf("Enter 3rd number: ");
    scanf("%f", &num3);
    
    // Conditions
    if (num1 > num2)
    {
        if (num1 > num3)
        {
            printf("%.2f is Greatest.", num1);
        }
        else
        {
            printf("%.2f is Greatest.", num3);
        }
    }
    else
    {
        if (num2 > num3)
        {
            printf("%.2f is Greatest.", num2);
        }
        else
        {
            printf("%.2f is Greatest.", num3);
        }
    }
    return 0;
}

Output:

Enter 1st number: 14
Enter 2nd number: 12
Enter 3rd number: 10

14.00 is Greatest.

*

إرسال تعليق (0)
أحدث أقدم