以下是C语言实现加减乘除的示例代码:

加法:

#include <stdio.h>

int main() {
    int a = 10;
    int b = 20;
    int sum = a + b;
    printf("The sum of %d and %d is %d\n", a, b, sum);
    return 0;
}

减法:

#include <stdio.h>

int main() {
    int a = 20;
    int b = 10;
    int difference = a - b;
    printf("The difference of %d and %d is %d\n", a, b, difference);
    return 0;
}

乘法:

#include <stdio.h>

int main() {
    int a = 10;
    int b = 20;
    int product = a * b;
    printf("The product of %d and %d is %d\n", a, b, product);
    return 0;
}

除法:

#include <stdio.h>

int main() {
    int a = 20;
    int b = 10;
    float quotient = (float)a / b;
    printf("The quotient of %d and %d is %.2f\n", a, b, quotient);
    return 0;
}

注意:在做除法时,需要将其中一个数转换为浮点数,以便得到准确的结果

用C语言写加减乘除

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

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