C Program To Find Largest Of 5 Numbers Using if-else
In this tutorial, we are going to see how to write a C program to find the largest of 5 numbers using if-else. In the following example, we ask the user to enter 5 numbers using scanf function, and then we consider the first input as the maximum. Then we compare it with other inputs.
C Program To Find Largest Of 5 Numbers Using if-else
#include <stdio.h>
int main()
{
int a,b,c,d,e;
printf("Enter 1st number: ");
scanf("%d",&a);
printf("Enter 2nd number: ");
scanf("%d",&b);
printf("Enter 3th number: ");
scanf("%d",&c);
printf("Enter 4th number: ");
scanf("%d",&d);
printf("Enter 5th number: ");
scanf("%d",&e);
int max = a;
if (b > max) max = b;
if (c > max) max = c;
if (d > max) max = d;
if (e > max) max = e;
printf("\nMax is %d", max);
return 0;
}
Output:
Enter 1st number: 5 Enter 2nd number: 12 Enter 3th number: 4 Enter 4th number: 6 Enter 5th number: 7 Max is 12




