-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathP63ARRAYS.cpp
More file actions
44 lines (32 loc) · 1007 Bytes
/
P63ARRAYS.cpp
File metadata and controls
44 lines (32 loc) · 1007 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Finding Max and Min element
#include<iostream>
#include<climits>
using namespace std;
int main(){
int n;
cout<<"enter the size of array you want";
cin>>n;
int arr[n];
for (int i = 0; i < n; i++)
{
cin>>arr[i] ; // getting input of all the array elements that the user wants
}
int maxNo= INT_MIN; // INT_MIN basically means the minimum possible value that is present in c++ (way to initialize)
int minNo= INT_MAX;
for (int i = 0; i < n; i++)
{
// if (arr[i]>maxNo)
// { // whenever the value given becomes greater than INT_MIN then max value gets updated
// maxNo=arr[i];
// }
// if (arr[i]<minNo)
// {
// minNo=arr[i];
// }
// instead of if we can use following
maxNo= max(maxNo,arr[i]);
minNo= min(minNo,arr[i]);
}
cout<<maxNo<<" "<<minNo<<endl;
return 0;
}