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

file name:- minmax1d.cpp

#include<iostream.h>
#include<conio.h>
#define N 10
void main(){
float list[N],min,max;
int i;
clrscr();
cout<<"Enter elements of array List"<<endl;
for(i=0;i<N;i++){
cout<<"Enter "<<i+1<<" element=";
cin>>list[i];
}
min=max=list[0];
for(i=1;i<N;i++){
if(min>list[i]) min=list[i];
if(max<list[i]) max=list[i];
}
cout<<"Minimum element = "<<min<<" and Maximum element = "<<max<<endl;
getch();
}

file name:- minmax1d.c

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

No comments:

Post a Comment

Priority Queue

Priority queue:-  It is a special type of queue which stores group of elements. Each element has a priority number associated with it. Prior...