c++输入两个整数,分别计算这两个数的和、差、积、商,并输出结果
时间: 2023-05-11 18:04:47 浏览: 781
好的,我可以回答这个问题。以下是计算两个整数的和、差、积、商的代码:
```c
#include <stdio.h>
int main() {
int num1, num2;
printf("请输入两个整数:\n");
scanf("%d %d", &num1, &num2);
int sum = num1 + num2;
int diff = num1 - num2;
int product = num1 * num2;
float quotient = (float)num1 / num2;
printf("和为:%d\n", sum);
printf("差为:%d\n", diff);
printf("积为:%d\n", product);
printf("商为:%f\n", quotient);
return 0;
}
```
输入两个整数后,程序会计算它们的和、差、积、商,并输出结果。注意,商需要转换为浮点数类型,否则会出现截断误差。
阅读全文