Problem Description
Display Largest Element of an arrayCODING ARENA::
#include <stdio.h>
int main()
{
int a[10],n,j,i,temp;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for (j=0;j<n;j++)
{
if(a[i]<a[j])
{
a[i]=temp;
a[i]=a[j];
temp=a[j];
}
}
}
printf ("%d",a[n-1]);
return 0;
}
Test Case 1
Input (stdin)5 1 2 3 4 54
Expected Output54
Test Case 2
Input (stdin)8 1 2 3 55 123 2 1 99
Expected Output123
No comments:
Post a Comment