Thursday, September 20, 2012

program to find the largest among an array

c program code for finding  the largest among an array...................
The program travels to all the elements in an array and find which is larger...
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10], n,i,t;
clrscr();
printf("Enter the limit\n");
scanf("%d",&n);
printf("Enter the numbers\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
t=a[0];
for(i=0;i<n;i++)
{
if(t<=a[i])
{
t=a[i];
}

}
printf("\n largest is\t%d",t);  //prints the largest


getch();
}

No comments:

Post a Comment