Menus

Thursday, 2 April 2020

C Program to find largest element in an array

#include<stdio.h>

void main()
{

int arr[100],size,i,max,location;

printf("Enter the number of elements in an array : ");
scanf("%d",&size);

for(i=0;i<size;i++)
{
printf("Enter array value ");
scanf("%d",&arr[i]);
}


max= arr[0];

for(i=1;i<size;i++)
{
if(arr[i]>max)
{
max=arr[i];
location=i+1;
}
}

printf("Maximum element in location %d and its value is %d \n",location,max);


}




No comments:

Post a Comment