-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8.1_array.cpp
74 lines (62 loc) · 1.21 KB
/
8.1_array.cpp
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include<iostream>
#include<climits>
using namespace std;
/*
int main(){
int array[4]={10,20,30,40};
cout<<array[2]<<endl;
return 0;
}
int main(){
int n;
cin>>n;
int array[n];
for (int i=0; i<=n-1; i++){
cin>>array[i];
}
for (int i=0; i<=n-1; i++){
cout<<array[i]<<" ";
}
return 0;
}
// maximum and minimum number from array with for loop
int main(){
int n;
cin>>n;
int max=INT_MIN;
int min=INT_MAX;
int array[n];
for (int i=0; i<=n-1; i++){
cin>>array[i];
}
for (int i=0; i<n; i++){
if (array[i]>max){
max=array[i];
}
if(array[i]<min){
min=array[i];
}
}
cout<<"Maximum element ="<<max<<endl;
cout<<"Minimum element ="<<min<<endl;
return 0;
}
*/
// max and min without loop
int main(){
int n;
cin>>n;
int max_No=INT_MIN;
int min_No=INT_MAX;
int array[n];
for (int i=0; i<=n-1; i++){
cin>>array[i];
}
for (int i=0; i<n; i++){
max_No=max(max_No,array[i]);
min_No=min(min_No,array[i]);
}
cout<<"Maximum element ="<<max_No<<endl;
cout<<"Minimum element ="<<min_No<<endl;
return 0;
}