-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path2*minmax.cpp
More file actions
50 lines (39 loc) · 820 Bytes
/
Copy path2*minmax.cpp
File metadata and controls
50 lines (39 loc) · 820 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
45
46
47
48
49
50
#include<iostream>
using namespace std;
int min(int arr[],int size){
int i,temp=arr[0];
for (i=0;i< size;i++){
if(temp > arr[i]){
temp=arr[i];
}
}
return temp;
}
int max(int arr[],int size){
int i,temp=arr[0];
for (i=0;i< size;i++){
if(temp < arr[i]){
temp=arr[i];
}
}
return temp;
}
void print(int arr[],int size){
for(int i=0;i<size;i++){
printf("%d ",arr[i]);
}
}
int main(){
cout<<"Enter the size of array and the array itself after pressing enter "<<endl;
int n;
scanf("%d",&n);
int arr[n];
for (int i=0;i<n;i++){
scanf("%d",&arr[i]);
}
print(arr,n);
cout<<endl;
cout<<max(arr,n)<<" is the max element\n";
cout<<min(arr,n)<<" is the min element\n";
return 0;
}