Write a program to find out a maximum number from three numbers. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Write a program to find out a maximum number from three numbers.

20th Jan 2017, 12:43 AM
Gajendra Singh Rathore
Gajendra Singh Rathore - avatar
8 Answers
+ 2
int main(){ if(num1 > num2 && num1 > num3){ cout << num1; } elif(num2 > num1 && num2 > num3){ cout << num2; } else{ cout << num3;}
20th Jan 2017, 12:51 AM
Aaron
Aaron - avatar
+ 2
If any numbers are the same, it won't work right. Try int main(){ if(num1 >= num2 && num1 >= num3){ cout << num1; } elif(num2 >= num1 && num2 >= num3){ cout << num2; } else{ cout << num3;} This should work, put in two of the same number and a smaller number
20th Jan 2017, 1:19 AM
Aaron
Aaron - avatar
+ 2
cin>>num1>>num2>>num3; max=num1; if(max<num2) num2=max; if(max<num3) num3=max; cout<<max;
20th Jan 2017, 5:50 AM
Megatron
Megatron - avatar
+ 1
Sidenote, I forgot that answer doesn't cover equal numbers, sorry
20th Jan 2017, 1:13 AM
Aaron
Aaron - avatar
+ 1
Is this for your homework? :|
20th Jan 2017, 1:32 AM
DaemonThread
DaemonThread - avatar
0
what do u mean I didn't understand can u explain
20th Jan 2017, 1:15 AM
Gajendra Singh Rathore
Gajendra Singh Rathore - avatar
0
equal no. means what
20th Jan 2017, 1:15 AM
Gajendra Singh Rathore
Gajendra Singh Rathore - avatar
0
yes bro it's my home work I am new to the c++ just joined this platform to learn c++ and Aaron it's very true Thanx bro
20th Jan 2017, 1:57 AM
Gajendra Singh Rathore
Gajendra Singh Rathore - avatar