diff --git a/Add Code Here/C++/Arrays/Maximum & minimum element.cpp b/Add Code Here/C++/Arrays/Maximum & minimum element.cpp index 1ec5ae28127..96d66846956 100644 --- a/Add Code Here/C++/Arrays/Maximum & minimum element.cpp +++ b/Add Code Here/C++/Arrays/Maximum & minimum element.cpp @@ -1,31 +1,24 @@ -#include +#include using namespace std; -int main(){ - -int a[5]={4,3,6,8,5}; -int i; -int max=a[0] ; -int min=a[0]; - -for( i=1;i<5;i++){ - -if(a[i]>max){ - -max=a[i]; - -} - -else if(a[i] max) { + max = a[i]; + } else if (a[i] < min) { + min = a[i]; + } + } + + cout << "Maximum element: " << max << endl; + cout << "Minimum element: " << min << endl; + + return 0; }