Exercises 2-9 of the title set of "C Language Programming (3rd Edition)" of Zhejiang University

Practice 2-9 Four arithmetic of integers (10 points)

This question requires writing a program to calculate and output the sum, difference, product, and quotient of two positive integers. The question ensures that the input and output are all within the integer range.
Input format:
Input two positive integers A and B in one line.
Output format:
output sum, difference, product and quotient in the order of the format "A operator B = result" in the 4 lines.
Input example:
3 2
Output example:
3 + 2 = 5
3-2 = 1
3 * 2 = 6
3/2 = 1

#include <stdio.h>

int main() {
    
    
    int a, b;
    if (scanf("%d %d", &a, &b) == 2) {
    
    
        printf("%d + %d = %d\n", a, b, a + b);
        printf("%d - %d = %d\n", a, b, a - b);
        printf("%d * %d = %d\n", a, b, a * b);
        printf("%d / %d = %d\n", a, b, a / b);
    }
    return 0;
}

Guess you like

Origin blog.csdn.net/DoMoreSpeakLess/article/details/109249281