C I need to compare 3 numbers and output the largest one I c
C++
I need to compare 3 numbers and output the largest one; I can only use 2 if blocks and I\'m not allowed to use \"else\" statements
Solution
Solution.cpp
#include <iostream>//header file for input output function
using namespace std;//it tells the cmpiler to link std namespace
int main()
{//main function
int num1,num2,num3;
cout<<\"Enter the number 1 :\";
cin>>num1;//key board inputting
cout<<\"Enter the number 2 :\";
cin>>num2;//key board inputting
cout<<\"Enter the number 3 :\";
cin>>num3;//key board inputting
if(num1>num2 && num1>num3)
{//comparing three numbers
cout<<num1<<\" is largest number\";
exit(0);
}
if(num2>num3 && num2>num1)
{//comparing three numbers
cout<<num2<<\" is largest number\";
exit(0);
}
cout<<num3<<\" is largest number\";
return 0;
}
output
Enter the number 1 :34
Enter the number 2 :23
Enter the number 3 :12
34 is largest number
