forked from DHEERAJHARODE/Hacktoberfest2025-Open-source-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaxMin.cpp
More file actions
30 lines (29 loc) · 668 Bytes
/
Copy pathMaxMin.cpp
File metadata and controls
30 lines (29 loc) · 668 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
cout << "\n<<<========MaxMin array========>>>\n";
int arr[5] = {10, 43, 12, 5, 300}, max, min;
cout << "\nThe given array is : \n";
for (int i = 0; i < 5; i++)
{
cout << arr[i] << " ";
}
min = arr[0];
max = arr[0];
for (int i = 0; i < 4; i++)
{
if (arr[i + 1] < min)
{
// max = min;
min = arr[i + 1];
}
if (arr[i + 1] > max)
{
// min = max;
max = arr[i + 1];
}
}
cout << "\nMaximum element is : " << max << "\nMinimum element is : " << min;
}