In: Computer Science
Write a function, which accept three integer values as arguments find the largest of three and then return the largest value to main program. Write a main program which will call the function by passing three integer values and print the value returned by the function.?
The largest() function is tested in the main function below
#include<iostream>
using namespace std;
int largest(int first, int second, int third){
int max = first;
if(second>first && second>third){
max = second;
}
else if(third>first && third>second){
max = third;
}
return max;
}
//Testing largest function
int main(){
int first, second, third;
cout<<"Enter the first integer\n";
cin>>first;
cout<<"Enter the second integer\n";
cin>>second;
cout<<"Enter the third integer\n";
cin>>third;
cout<<"The largest integer is: "<<largest(first, second, third)<<endl;
}
int largest(int first, int second, int third){
int max = first;
if(second>first && second>third){
max = second;
}
else if(third>first && third>second){
max = third;
}
return max;
}