0

Can any one help with finding the maximum value in an array of 5 elements?

13th Nov 2016, 8:10 PM
Pa Modou Faal
4 ответов
+ 3
as a function for any size of array int getMax(int arr[], int size){ int max = arr[0]; for(int i = 0; i < size; i++){ if(arr[i] > max) max = arr[i]; } return max; }
13th Nov 2016, 8:18 PM
Burey
Burey - avatar
+ 2
if you are asking you to work with it: int main(){ int arr[5] = {4, -74, 82, 411, -1337}; int max = getMax(arr, 5); cout << max << endl; return 0; }
13th Nov 2016, 8:27 PM
Burey
Burey - avatar
0
Thanks bro for so if I need to find the list value what do I do
13th Nov 2016, 8:21 PM
Pa Modou Faal
0
int main () { int arr [5]; for (int I=0 ; I <5; I ++) cin>> arr [I]; int max=arr [0]; for (int I=1; I <5; I++) { if(arr [I]> max) max=arr [I]; } cout <<max; }
13th Nov 2016, 8:28 PM
ROHAN JOSHI
ROHAN JOSHI - avatar