Input 10 numbers and print the smallest using while loop in C
while Loop - Question 3
In this question, we will see how to input 10 numbers and print the smallest among them in C programming using while loop. To know more about while loop click on the while loop lesson.
Q3) Write a program in C to input 10 numbers and print the smallest among them using while loop.
Program
#include <stdio.h>
#include <conio.h>
int main()
{
int i=1,n,sm;
printf("Enter 10 numbers\n");
while(i<=10)
{
scanf("%d",&n);
if(i==1)
{
sm=n; // store the first number
}
else if(n<sm) // compare the previous stored number with the latest entered number
{
sm=n;
}
i=i+1;
}
printf("Smallest Number = %d",sm);
return 0;
}
Output
Enter 10 numbers 12 6 48 95 3 11 27 36 54 89 Smallest Number = 3