/* * 示例4:算术运算(Arithmetic Operations) * 功能:学习 C 语言中的基本算术运算符 */ #include int main() { int a = 10; int b = 3; // 加法运算 int sum = a + b; printf("%d + %d = %d\n", a, b, sum); // 减法运算 int diff = a - b; printf("%d - %d = %d\n", a, b, diff); // 乘法运算 int product = a * b; printf("%d * %d = %d\n", a, b, product); // 除法运算(注意:整数除法会丢弃小数部分) int quotient = a / b; printf("%d / %d = %d(整数除法,丢弃小数)\n", a, b, quotient); // 取余运算(求余数) int remainder = a % b; printf("%d %% %d = %d(取余数)\n", a, b, remainder); // 浮点数除法(保留小数) float result = (float)a / b; // (float)a 把 a 转换为浮点数 printf("%d / %d = %.2f(浮点数除法)\n", a, b, result); // 自增和自减运算 int count = 5; count++; // count 加 1,等价于 count = count + 1 printf("自增后 count = %d\n", count); count--; // count 减 1 printf("自减后 count = %d\n", count); return 0; }