0
Can any one help with finding the maximum value in an array of 5 elements?
4 Antworten
+ 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;
}
+ 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;
}
0
Thanks bro
for so if I need to find the list value what do I do
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;
}