Find the largest element and its position in array
#include<stdio.h>
main()
{
int A[10];
int largest, position, num, i;
printf("\nEnter the number of elements you want in array : ");
scanf("%d",&num);
printf("\nEnter the %d number for array.\n\n",num);
for(i=0;i<num;i++)
{
scanf("%d",&A[i]);
}
largest=A[0];
for(i=1;i<num;i++)
{
if(largest<A[i])
{
largest=A[i];
position=i+1;
}
}
printf("\nThe largest element is %d.\n",largest);
printf("\nPosition of the largest element %d is %d.\n\n",largest,position);
getch();
}
Comments
Post a Comment