C program to find minimum and maximum element exist in 1D array.

#include<stdio.h>
#include<conio.h>
#define N 5
void main(){
int list[N],i,min,max;
clrscr();
printf("Enter Elements of list \n");
for(i=0;i<N;i++){
printf("Enter %d Element = ",i+1);
scanf("%d",&list[i]);
}
min=max=list[0];
for(i=1;i<N;i++){
if(list[i]>max) 
max=list[i];
if(list[i]<min) 
min=list[i];
}
printf("Minimum Element= %d and Maximum Element =%d\n",min,max);
getch();
}

No comments:

Post a Comment