C++ program to find minimum and maximum element in array

without using function


#include<iostream>
using namespace std;
int main()
{
int a[100],n,i,min,max;
cout<<"Enter the size of array\n";
cin>>n;
cout<<"Enter the elements one by one\n";
for(i=0;i<n;i++)
cin>>a[i];
min=a[0];

for(i=0;i<n;i++)
{

if(a[i]<min)
{
min=a[i];
}
}
cout<<"min in the array is "<<min<<"\n";
max=a[0];
for(i=0;i<n;i++)
if(a[i]>max)
{
max=a[i];
}
cout<<"max in the array is "<<max;
}


OUTPUT:-

Enter the size of array
3
Enter the elements one by one
5
8
4
min in the array is 4
max in the array is 8

Comments

Popular posts from this blog

cpanel exam CPSP Answers

How to install zimbra collaboration suite 8.8.11 on CentOS 7

awstats installation