Program for find the greatest number in an array in c language.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],i,large,n;
int loc=1;
clrscr();
printf("enter the size of array=");
scanf("%d",&n);
printf("enter elements of array=");
for(i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
printf(" array elements are=\n");
for(i=0; i<n; i++)
{
printf("%d\n",a[i]);
}
large=a[0];
for(i=1; i<n; i++)
{
if(a[i]>large)
{
large=a[i];
loc++;
}
}
printf("the largest element is=%d",large);
printf(" the largest element's location is=%d",loc);
getch();
}
■》 Output->
enter the size of array=5
enter elements of array=>
23
2
67
30
54
array elements are=>23 2 67 30 54
the largest element is=>67
the largest element's location is=>2
Comments
Post a Comment