Question : Write a C++ program to find Largest of Three Numbers?
Explain: C++ Question about compare three input from user then program tells us which number is Greater. We will used simple If-else statement for resolving solution.
Solution:
/************************************************************
C++ Program for Largest number from three numbers using if-else
*************************************************************
***************** By cpplanguage.com *********************/
#include <iostream>
using namespace std;
int main()
{
double value1, value2, value3;
cout<<"Enter a Value 1: \n";
// Getting input Value1
cin>>value1;
cout<<"Enter a Value 2: \n";
// Getting input Value2
cin>>value2;
cout<<"Enter a Value 3: \n";
// Getting input Value3
cin>>value3;
//compare value 1 with value 2 & 3
if((value1 >= value2) && (value1 >= value3))
cout << "Largest number: " << value1<<endl;
//compare value 2 with value 1 & 3
else if ((value2 >= value1) && (value2 >= value3))
cout << "Largest number: " << value2<<endl;
else
//output if all condition false then value 3 is largest number
cout << "Largest number: " << value3<<endl;
return 0;
}
Output: