Source code:
//Write a C program to find the largest element of a given array
#include <stdio.h>
int main()
{
int j, array[5];
for(j=0;j<5;++j)
{
printf("Enter the value for %d: ",j);
scanf("%d",&array[j]);
}
int i, largest;
largest = array[0];
for(i = 0; i < 5; i++)
{
if( largest < array[i] )
largest = array[i];
}
printf("%d", largest);
return 0;
}
Output:
No comments:
Post a Comment