有两个整形变量a,b,它们的值分别是3,5,试编写程序计算它们的和、差、积,商
时间: 2023-04-03 10:03:55 浏览: 91
好的,这是一个简单的数学问题。计算它们的和、差、积和商的程序如下:
#include <stdio.h>
int main() {
int a = 3, b = 5;
int sum = a + b;
int diff = a - b;
int product = a * b;
int quotient = a / b;
printf("a + b = %d\n", sum);
printf("a - b = %d\n", diff);
printf("a * b = %d\n", product);
printf("a / b = %d\n", quotient);
return 0;
}
程序的输出结果如下:
a + b = 8
a - b = -2
a * b = 15
a / b = 0
其中,sum、diff、product和quotient分别表示a和b的和、差、积和商。注意,由于a和b都是整数,所以在计算商时会进行整数除法,结果会向下取整。
阅读全文