0

C++program to find largest of 5 number in array using the function

13th Dec 2017, 1:50 PM
Aakash Alaria
Aakash Alaria - avatar
3 Answers
+ 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; }
13th Dec 2017, 2:05 PM
Cool Codin
Cool Codin - avatar
+ 1
I said using funtion
13th Dec 2017, 2:02 PM
Aakash Alaria
Aakash Alaria - avatar
+ 1
In main: int arr[5]; for(int& i : arr) cin>>i; //Read the array using a loop. cout<<max_element(arr,arr+5);
13th Dec 2017, 2:15 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar