-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathminOrMaxElement.cpp
68 lines (54 loc) · 981 Bytes
/
minOrMaxElement.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
#include<iostream>
using namespace std;
int min(int a[], int n)
{
int s=a[0];
for(int i=1; i<n; i++)
{
if(a[i]<s)
{
s = a[i];
}
}
return s;
}
int max(int a[], int n)
{
int m=a[0];
for(int i=1; i<n; i++)
{
if(a[i]>m)
{
m = a[i];
}
}
return m;
}
int main()
{
int n, c;
cout<<"Enter size of array:\n";
cin>>n;
int a[n];
cout<<"Enter elements in array:\n";
for(int i=0; i<n; i++)
{
cin>>a[i];
}
cout<<"Enter 1 to find max element in array.\nEnter 2 to find min element in array.\n";
cout<<"Enter your choice:\n";
cin>>c;
switch(c)
{
case 1:
cout<<"Max element is: "<<max(a, n)<<"\n";
break;
case 2:
cout<<"Min element is: "<<min(a, n)<<"\n";
break;
default:
cout<<"Wrong choice!\n";
break;
}
return 0;
}