如何編寫C++程序,可以讓用戶輸入三個數字,那三2 higest之間找到,寫不便,如:中5,3,4總和5和4是9!C++三個數字之和之間的兩個highers不循環和數組
我想媒體鏈接,但我得到了太多,如果別人的,它看起來非常糟糕,甚至不是在所有情況下正常工作:/
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float n1, n2, n3;
cout << "Enter three numbers: ";
cin >> n1 >> n2 >> n3;
if(n1 >= n2 && n1 >= n3)
{
if(n2>=n1 && n2>=3)
cout << "Sum of 2 highest between this three numbers is: " << cout<<n1+n2;
}
if(n1 >= n2 && n1 >= n3)
{
if(n3>=n1 && n3>=n2)
cout << "Sum of 2 highest between this three numbers is: " << cout<<n1+n3;
}
if(n2 >= n1 && n2 >= n3)
{
if(n3 >= n1 && n3 >= n2) {
cout << "Sum of 2 highest between this three numbers is: " << cout<<n3+n2;
}
}
if(n3 >= n1 && n3 >= n2)
{
if(n2 >= n1) {
cout << "Sum of 2 highest between this three numbers is: " << cout<<n3+n2;
}
}
if(n3 >= n1 && n3 >= n2)
{
if(n1>= n2) {
cout << "Sum of 2 highest between this three numbers is: " << cout<<n3+n1;
}
}
return 0;
}
我不知道它是否會有幫助,但是如果'n1> n2 && n2> n3'那麼這也意味着'n1> n3'。 –
@Someprogrammerdude來吧,讓我們在這裏找到2個最高的數字:D –
一些lambda與stable_sort可能會得心應手,你接受使用向量? – user