How to find greatest element?
CODE
How to find greatest
element?
//Write a program to
find the greatest element in an array…
int
main()
{
int max,n,i,a[10];
printf("\n enter n:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n element at
a[%d]:",i);
scanf("%d",&a[i]);
}
max=a[0];
for(i=1;i<n;i++)
{
if(a[i]>max)
max=a[i];
}
printf("\n maximum=%d",max);
}
Output:
enter n:5
element at a[0]:8
element at a[1]:5
element at a[2]:4
element at a[3]:7
element at a[4]:6
maximum=8
How to find greatest element?
Reviewed by Unknown
on
December 31, 2018
Rating:
No comments:
If you have any doubt or query ,comment below: