Sita has been promoted to a Team Leader and she has been shifted to Multimedia Team. As she needs to extensively work on audio, image and video signals, she is planning to spend a day in mastering the basics of 1-D and 2-D arrays.
Can you please help her out?
Write a program to find the maximum element in an array.
Input Format:
Input consists of n+1 integers.
The first line of the input contains an integer corresponds to ‘n’, the size of the array.
The next ‘n’ integers correspond to the elements in the array. Assume that the maximum value of n is 15.
Output Format:
Refer sample input and output for formatting details.
Sample Input 1:
5
2
3
6
8
1
Sample Output 1:
8 is the maximum element in the array
Program Code:
#include<stdio.h>
int main()
int i,n=0,a;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a);
if(n<a)
{
n=a;
}
}
printf("%d is the maximum element in the array",n);
return 0;
}
Post A Comment:
0 comments: