In: Computer Science
Please write a C++ program to find the largest
number among three numbers using nested if...else
statements
You need to prompt the user to enter three integer numbers from the
keyboard, and then display the largest number among the
three.
Please create a function to find the largest number among three
numbers, and call the maxAmongThree function in the main
function.
#include <iostream>
using namespace std;
// function declaration
int MaxAmongThree(int n1, int n2,int n3);
int main() {
float n1, n2, n3,result; //local variables....
cout << "Enter three numbers: "; //take input from
user...
cin >> n1 >> n2 >> n3; //three numbers...
result=MaxAmongThree( n1,n2,n3); //function calling...
cout<<"Largest among three number is "<<result; //print
final result....
}
//function definition...
int MaxAmongThree(int n1,int n2,int n3){
//nested if else....
if((n1 >= n2) && (n1 >= n3))
return n1; //return n1..
else if ((n2 >= n1) && (n2 >= n3))
return n2; //return n2...
else
return n3; //return n3...
}