this program will print Largest number from 10 entered numbers by user.So, how it works? I have 2 integers and 1 integer array.after clrscr(); program will scan 10 integers from user and it will be stored in array named n.then num=0 is because when program will start checking from first number and obviously before checking and comparing other number we want some value which is 0 0<n[i] then new value of num will be value of n[i] then this loop will be continued till n[9] and at last program will print value of num which is Largest.Now let us see program.
Program:
#include<stdio.h>
#include<conio.h>
main()
{
int n[9],num=0,i;
clrscr();
for(i=0;i<=9;i++)
{
printf("Enter number %d: ",i+1);
scanf("%d",&n[i]);
}
for(i=0;i<=9;i++)
{
if(n[i]>num)
{
num=n[i];
}
}
printf("\nGreatest number is %d",num);
getch();
}
Output:
Program:
#include<stdio.h>
#include<conio.h>
main()
{
int n[9],num=0,i;
clrscr();
for(i=0;i<=9;i++)
{
printf("Enter number %d: ",i+1);
scanf("%d",&n[i]);
}
for(i=0;i<=9;i++)
{
if(n[i]>num)
{
num=n[i];
}
}
printf("\nGreatest number is %d",num);
getch();
}
Output: