Skip to content
Home » C program to find the largest of three numbers using nested if-else statements

C program to find the largest of three numbers using nested if-else statements

Learn about C program to find the largest of three numbers using nested if-else statements in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

C program to find the largest of three numbers using nested if-else statements

Source code:

#include<stdio.h>
int main()
{
   float num1, num2, num3;

   printf("Enter three numbers: ");
   scanf("%d %d %d",&num1,&num2,&num3);

   if(num1 >= num2)
   {
     if(num1 >= num3)
       printf("Largest Number=%d\n",num1);

     else
       printf("Largest Number=%d\n",num3);
   }

   else
   {
     if(num2>=num3)
       printf("Largest Number=%d\n",num2);

     else
       printf("Largest Number=%d\n",num3);
   }

   return 0;
}

Output:

Enter three numbers: 4 1 7
Largest Number=7

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
C Program to Find Grade of Student using nested if-else statements
Hello World Program in C