Site icon Matistics

C Program to Find the Minimum and Maximum Numbers in an Array. The program will prompt the user to input the array size and the array elements

#include<stdio.h>
int main(){
int n;
printf("Enter the length of array ");
scanf("%d",&n);
int a[n];
printf("Enter the elements of array\n");
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
int m = a[0];
for(int j=0;j<n;j++){
if(a[j] > m){
m = a[j];
}
}
printf("Maximum: %d\n",m);
m = a[0];
for(int k=0;k<n;k++){
if(a[k] < m){
m = a[k];
}
}
printf("Minimum: %d",m);
return 0;
}

Exit mobile version