In: Computer Science
In C++ create a simple larger3( ) function that takes 3 positive numbers as parameters and returns the largest value of the three numbers.
#include <iostream>
#include <conio.h>
using namespace std;
int largest3(int,int,int);//function declaration
int main()
{
int n1,n2,n3; //declare the variables
cout<<"Enter the first number:";
cin>>n1;//taking input from user for n1
cout<<"Enter the second number: ";
cin>>n2;//taking input from user for n2
cout<<"Enter the third number: ";
cin>>n3;//taking input from user for n3
int lar=largest3(n1,n2,n3);//function calling
cout<<"largest number is: "<<lar;//printing the
output
getch();
return 0;
}
int largest3(int n1, int n2, int
n3){//function definition & function for finding largest
number
if(n1>=n2){
if(n1>=n3){
return n1;
}
else{
return n3;
}
}
else{
if(n2>n3){
return n2;
}
else{
return n3;
}
}
Feel free to ask any question
Please give your positive feedback