如果你想将两个最大值相加,可以使用以下代码:

#include <iostream>
using namespace std;

int main() {
    int num1, num2, max1, max2, sum;
    
    cout << "Enter the first number: ";
    cin >> num1;
    cout << "Enter the second number: ";
    cin >> num2;
    
    if (num1 > num2) {
        max1 = num1;
        max2 = num2;
    } else {
        max1 = num2;
        max2 = num1;
    }
    
    sum = max1 + max2;
    
    cout << "The sum of the two maximum numbers is: " << sum << endl;
    
    return 0;
}

这个程序首先要求用户输入两个数字,然后使用if-else语句找到其中较大的数字,并将它们相加。最后,程序会输出这两个最大数字的和

最大值相加c++

原文地址: https://www.cveoy.top/t/topic/igp4 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录