-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6997 from sulaemanahmed/patch-7
Update Maximum & minimum element.cpp
- Loading branch information
Showing
1 changed file
with
19 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,24 @@ | ||
#include<iostream> | ||
#include <iostream> | ||
|
||
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]<min){ | ||
|
||
min=a[i]; | ||
|
||
} | ||
} | ||
cout<<max<<endl; | ||
cout<<min<<endl; | ||
return 0; | ||
|
||
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] < min) { | ||
min = a[i]; | ||
} | ||
} | ||
|
||
cout << "Maximum element: " << max << endl; | ||
cout << "Minimum element: " << min << endl; | ||
|
||
return 0; | ||
} | ||
|