题解 | #简单运算#

简单运算

https://www.nowcoder.com/practice/23c9b22d40fa4d7698a1306fb0c9f975

#include <iostream>
using namespace std;

int main() {
    int a, b;

    // 输入两个整数
    std::cin >> a >> b;

    // 计算和、差、积、商、模
    int sum = a + b;
    int difference = (a > b) ? (a - b) : (b - a);
    int product = a * b;
    int quotient = (a > b) ? (a / b) : (b / a);
    int remainder = (a > b) ? (a % b) : (b % a);

    // 输出结果
    std::cout << sum <<" " << difference << " " << product << " " << quotient << " " << remainder << " " << std::endl;

    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务