Comparing 3 nos | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Comparing 3 nos

Hi all... Below is my code of comparing 3 numbers.. I have to check all 4 possibilites in "single code" 1)tell largest no 2) tell you entered equal nos 3)tell smallest number 4)show equality of numbers if any two numbers have same value... First two possibilities are achieved but confused about 3 and 4 Kindly guide me... /////////////////////////////////////////// #include <iostream> using namespace std; int main() { int n1,n2,n3; cout<<"enter three values\n"; cin>>n1>>n2>>n3; if ((n1==n2) && (n2==n3)) cout <<"all numbers are equal\n"<< n1<<" "<<n2 <<" "<< n3; else if((n1>=n2) && (n1>=n3)) { cout<<" largest no \n"<<n1; } else if((n2>=n1) && (n2>=n3)) { cout<<"largest no\n"<<n2; } else { cout<<"largest no"<<" "<<n3; } return 0; }

13th Nov 2018, 4:22 PM
Usman Zafar
Usman Zafar - avatar
3 Answers
+ 8
For task 3 do so same thing but with less than symbol i.e (<) For task 4 you need to check equality of two values separately like if(n1 == n2) // Statements else if (n1 == n3) // Statements else if(n2 == n3) // Statements Note that in your code when you are comparing values for largest no. you don't need to put the equal sign because you will be checking for it in the last task.
13th Nov 2018, 6:51 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 8
Welcome
15th Nov 2018, 6:05 AM
blACk sh4d0w
blACk sh4d0w - avatar
0
Thanks nautaxh ahmad
15th Nov 2018, 5:37 AM
Usman Zafar
Usman Zafar - avatar