0
C++program to find largest of 5 number in array using the function
3 odpowiedzi
+ 9
#include <iostream>
using namespace std;
int largest() {
int array[5] = {5, 123, 5, 9, 1};
int temp = 0;
for(int i = 0;i <= 5;i++)
{
if(array[i] > temp)
temp = array[i];
}
return temp;
}
int main()
{
cout << largest();
return 0;
}
+ 1
I said using funtion
+ 1
In main:
int arr[5]; for(int& i : arr) cin>>i;
//Read the array using a loop.
cout<<max_element(arr,arr+5);