Q :
Write a C++ program that asks the user to enter
three integers and then
displays the largest one.
Example :
if the user enter ( 7, 2 ,5) the largest number will be 7
Or if user enter ( 2 , 5 , 7 ) the largest number will be 7
Or if user enter ( 7, 5 ,2) the largest number will be 7
In general it does not matter the order of the entered numbers is
the most important thing that shows me the largest number .
#include <iostream>
using namespace std;
int main() {
int n1, n2, n3,max;
cout << "Enter three numbers: ";
cin >> n1 >> n2 >> n3;
if(n1 >= n2 && n1 >= n3)
max=n1;
if(n2 >= n1 && n2 >= n3)
max=n2;
if(n3 >= n1 && n3 >= n2)
max=n3;
cout<<"Largest Number = "<<max;
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.