Write a program to find the minimum element in an array.
Input Format:
Input consists of n+1 integers. The first 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 output for details.
Sample Input 1:
5
2
3
6
8
1
Sample Output 1:
1 is the minimum element in the array
Code:
#include<stdio.h>
int main(){
int n, a[20], i,min=1;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
min=a[0];
for(i=1;i<n;i++)
{
if(a[i]<min)
min=a[i];
}
printf("%d is the minimum element in the array",min);
return 0;
}
No comments:
Post a Comment