下面是一个简单的C语言程序,它演示了如何使用基本的算术运算符(`+`、`-`、`*`、`/`、`%`)来进行算术运算:
```c
#include
int main() {
int a = 10;
int b = 3;
int sum, difference, product, quotient, remainder;
// 加法
sum = a + b;
printf("Sum of %d and %d is %d\n", a, b, sum);
// 减法
difference = a - b;
printf("Difference of %d and %d is %d\n", a, b, difference);
// 乘法
product = a * b;
printf("Product of %d and %d is %d\n", a, b, product);
// 除法
if (b != 0) { // 确保除数不为0
quotient = a / b;
printf("Quotient of %d divided by %d is %d\n", a, b, quotient);
} else {
printf("Error: Division by zero is not allowed.\n");
}
// 取余(模运算)
remainder = a % b;
printf("Remainder of %d divided by %d is %d\n", a, b, remainder);
return 0;
}
```
这个程序首先定义了两个整数变量`a`和`b`,然后定义了五个其他变量来存储加法、减法、乘法、除法和取余的结果。对于每种运算,程序都进行了相应的计算,并使用`printf`函数打印结果。注意,在进行除法运算时,程序首先检查除数是否为零,以避免除以零的错误。