-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy path01_max_value_in_array.cpp
51 lines (39 loc) · 1.28 KB
/
01_max_value_in_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
/*
Max Value in Array
Take as input N, the size of array. Take N more inputs and store that in an array.
Write a function which returns the maximum value in the array. Print the value returned.
1.It reads a number N.
2.Take Another N numbers as input and store them in an Array.
3.calculate the max value in the array and return that value.
Input Format: First line contains integer n as size of array.
Next n lines contains a single integer as element of array.
Constraints: N cannot be Negative. Range of Numbers can be between -1000000000 to 1000000000
Output Format: Print the required output.
Sample Input: 4
2
8
6
4
Sample Output: 8
Explanation: Arrays= {2, 8, 6, 4} => Max value = 8 .
*/
#include <iostream>
#include <climits>
using namespace std;
int main() {
int range;
cout << "Enter array range: ";
cin >> range;
int arr[range];
int maxVal = INT_MIN;
cout << "Enter array elements: ";
for(int idx=0; idx<=range-1; idx++){
cin >> arr[idx];
if(arr[idx]>maxVal){
maxVal = arr[idx];
}
}
cout << "Max array value: ";
cout << maxVal <<endl;
return 0;
}