-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path09_Min_Max_INArray.cpp
60 lines (46 loc) · 1.14 KB
/
09_Min_Max_INArray.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
#include <iostream>
using namespace std;
void ArrayMax(int arr[], int n){
//
// initially max value minimum hai
// koi agar isse bada hota hai to usko hum bada bana denge.
int maxi=INT32_MIN;
int index=0;
for(int i=0; i<n; i++){
maxi=max(maxi,arr[i]);
index=i;
// if(arr[i]>maxi){
// maxi=arr[i];
// index=i;
// }
}
cout<<maxi<<" "<<index;
return ;
}
int ArrayMin(int arr[], int n){
//
int mini=INT32_MAX;
for(int i=0; i<n; i++){
mini=min(mini,arr[i]);
// if(arr[i]<mini){
// mini=arr[i];
// }
}
return mini;
}
int main(){
int size;
cout<<"enter the size of the array:";
cin>>size;
cout<<"enter the array elements:";
// int num[size]; this is not good practice
int num[100]; // this is good practice
// Taking input in array;
for(int i=0; i<size; i++){
cin>>num[i];
}
// cout<<"maximum value of array is:"<<ArrayMax(num, size)<<endl;
// cout<<"minimum value of array is:"<<ArrayMin(num, size)<<endl;
ArrayMax(num,size);
return 0;
}