酷代码 AI
菜单
全部AI  /  热门  /  AI写代码神器
服务商

已知有两个整数,请使用if-else选择结构将它们中的较大数选择出来,存到max变量中;将较小数选择出来,存到min变量中,并将选择结果输出。 输入格式: 只有一行,为用空格分隔的两个整数。测试用例保证这两个数可以用int类型存储。 输出格式: 如果输入的两个整数相等,则输出“the two numbers are equal.”,如果不等则按如下格式输出:“the larger number is 100, the smaller number is 25.”(假设输入的两个数分别为100和25)。 c++语言

以下是使用 C++语言解决此问题的代码: ```cpp #include <iostream> int main() { int num1, num2, max, min; std::cout << "请输入两个整数,用空格分隔: "; std::cin >> num1 >> num2; if (num1 == num2) { std::cout << "the two numbers are equal." << std::endl; } else { if (num1 > num2) { max = num1; min = num2; } else { max = num2; min = num1; } std::cout << "the larger number is " << max << ", the smaller number is " << min << "." << std::endl; } return 0; } ``` [2024-10-10 23:00:17 | AI写代码神器 | 191点数解答]

相关提问