Tuesday 11 March 2014

Program In C++ To Find Maximum And Minimum In 1D Array

#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int a[20],n,i,max,min;
cout<<"\nEnter Size Of Array: ";
cin>>n;
cout<<"\nEnter Array: ";
for(i=0;i<n;i++)
cin>>a[i];
max=min=a[0];
for(i=0;i<n;i++)
{ if(a[i]<min)
min=a[i];
if(a[i]>max)
max=a[i];
}
cout<<"\nMinimum In Array Is: "<<min;
cout<<"\nMaximum In Array Is: "<<max;
getch();
}

No comments:

Post a Comment