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

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

Learn about C program to find the largest of three numbers using if 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 if statements

Program:

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

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

   max = num1;
   if(num2>max) max = num2;
   if(num3>max) max = num3;

   printf("Largest number = %d", max);

   return 0;
 }

Output:

Enter three numbers: 5 2 8
Largest number = 8

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 Largest of Three Numbers Using AND (&&) operator
C program to find the largest of three numbers using nested if-else statements