C Program to find the largest element in an array and the position of its occurrence.
Code:
#include <stdio.h>
#include <conip.h>
void main()
{
int a[100];
int largest,position,num,index;
scanf("%d",&num);
for(index=0;index<num;index++)
scanf("%d",&a[index]);
largest=a[0];
position=0;
for(index=1;index<num;index++)
{
if(largest<a[index])
{
largest = a[index];
position=index;
}
}
printf("Largest element in the array is %d \n", largest);
printf("Largest element's position in the array %d\n", position+1);
return 0;
Getch();
}