C Program To Find Smallest Of 5 Numbers Using if-else
In this tutorial, we are going to see how to write a C program to find the smallest 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 minimum. Then we compare it with other inputs.
C Program To Find Smallest 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 min = a;
if (b < min) min = b;
if (c < min) min = c;
if (d < min) min = d;
if (e < min) min = e;
printf("\nMin is %d", min);
return 0;
}
Output:
Enter 1st number: 5 Enter 2nd number: 12 Enter 3th number: 4 Enter 4th number: 6 Enter 5th number: 7 Min is 4




