This is program to find Minimum And Maximun in a list of array:
#include<iostream.h>
#include<conio.h>
void main()
{
int n,i,a[100],max=0,min;
cout<<"enter the number of elements\n";
cin>>n;
cout<<"enter the elements of array\n";
for(i=0;i<n;i++)
{
cin>>a[i];
}
for(i=0;i<n;i++) {
if(a[i]>max){
max=a[i];
}
}
min=max;
cout<<"the maximum element is\n"<<max;
for(i=0;i<n;i++){
if(a[i]<min){
min=a[i];
}
}
cout<<"\nthe minimum element is\n"<<min;
getch();
}
Output:
No comments:
Post a Comment