C++ Program to Find Maximum of Three Numbers
Write C++ Program to Find Maximum of Three Numbers
// CPP Program to Find Maximum of Three Numbers
#include <iostream>
using namespace std;
int main()
{
int n1, n2, n3;
cout << "Enter the number 1 :--> ";
cin >> n1;
cout << "Enter the number 2 :--> ";
cin >> n2;
cout << "Enter the number 3 :--> ";
cin >> n3;
if(n1 > n2)
{
if(n1 > n3)
{
cout << "\nThe largest number among " << n1 << ", " << n2 << " and " << n3 << " is " << n1;
}
else if(n3 > n1)
{
cout << "\nThe largest number among " << n1 << ", " << n2 << " and " << n3 << " is " << n3;
}
}
if(n2 > n1)
{
if(n2 > n3)
{
cout << "\nThe largest number among " << n1 << ", " << n2 << " and " << n3 << " is " << n2;
}
else if(n3 > n2)
{
cout << "\nThe largest number among " << n1 << ", " << n2 << " and " << n3 << " is " << n3;
}
}
return 0;
}
Output:
Enter the number1 :--> 89
Enter the number2 :--> 56
Enter the number3 :--> 98
The largest number among <89 ,56 ,98> is 98