In this program, we've to find the largest number from a series of numbers "a[10]", each and every number will be compared to each other, for loop and if else functions will be used . 1st for loop is used to get the inputs in array & 2nd one is used to compare the no.s of array but if no. is greater than max then that no. will be max.Using this we can find the largest no. in array..
Program to find largest no.
#include<stdio.h>
#include<conio.h>
void main()
{ int n,i,max=0,a[10];
clrscr();
printf("\n program to find largest among n no.s");
printf("\n\n enter no. of numbers : ");
scanf("%d",&n);
printf("\n enter no.s now : \n");
for(i=0;i<n;i++)
{ printf("enter a[%d] = ",i);
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{ if(a[i]>max)
{ max = a[i]; }
}
printf("\n\n largest no.s among all = %d",max);
getch();
}

No comments:
Post a Comment
Guys if you think something is wrong or should be edit than please do comment.