Monday, February 8, 2021

Program To Find the maximum and minimum Element in array Using C++

Find the maximum and minimum Element in array Using C++



#include<iostream.h>
#include<conio.h>
{
  int a[5], i, max, min;
  cout<<"Enter the maximum element of array";
  for(i=0; i<5;i++)
  cint>>a[i];
  cout<<"the array is : ";
  for(i=0; i<5; i++)
  {  
     cout<<a[i];
     max = a[0];
     min = a[0];
     for(i=0; i<5; i++)
     if(max<a[i])
     max = a[i];
     if(min>a[i])
     min = a[i];
 }
 cout<<"the maximum number is :"<<max;
 cout<<"the minimum number is :"<<min;
 getch();
}


Output : 


0
1
2
3
4
5
6
7
8
9
the array is : 0 1 2 3 4 5 6 7 8 9 
the maximum number is 9
the minimum number is 0

No comments:

Post a Comment