两个正整数相加 相减 相乘的代码
时间: 2023-04-03 16:03:11 浏览: 132
大整数的四则运算高质量C语言程序.doc
以下是两个正整数相加、相减、相乘的代码:
相加:
```c
#include <stdio.h>
int main() {
int a, b, sum;
printf("请输入两个正整数:\n");
scanf("%d%d", &a, &b);
sum = a + b;
printf("%d + %d = %d\n", a, b, sum);
return 0;
}
```
相减:
```c
#include <stdio.h>
int main() {
int a, b, diff;
printf("请输入两个正整数:\n");
scanf("%d%d", &a, &b);
diff = a - b;
printf("%d - %d = %d\n", a, b, diff);
return 0;
}
```
相乘:
```c
#include <stdio.h>
int main() {
int a, b, product;
printf("请输入两个正整数:\n");
scanf("%d%d", &a, &b);
product = a * b;
printf("%d * %d = %d\n", a, b, product);
return 0;
}
```
阅读全文