Input 10 numbers and print the largest using for loop in C
for Loop - Question 8
In this question, we will see how to input 10 numbers and print the largest number among them in C programming using for loop. To know more about for loop click on the for loop lesson.
Q8) Write a program in C to input 10 numbers and print the largest number among them using for loop.
Program
#include <stdio.h>
#include <conio.h>
int main()
{
int i,n,lar;
printf("Enter 10 numbers\n");
for(i=1; i<=10; i=i+1)
{
scanf("%d",&n);
if(i==1)
{
lar=n; // store the first number
}
else if(n>lar) // compare the previous stored number with the latest entered number
{
lar=n;
}
}
printf("Largest Number = %d",lar);
return 0;
}
Output
Enter 10 numbers 15 3 6 9 84 21 34 59 5 12 Largest Number = 84