在线编译器 C

#include <stdio.h> int main() { int price, quantity, discount; scanf("%d%d%d", &price, &quantity, &discount); double total; total = price * quantity * (100 - discount) / 100.0; printf("C=%.2f ", total); return 0; }
这段代码的功能是:输入商品单价、数量和折扣百分比,计算折扣后的总价并输出。它使用了整数输入和浮点数计算。

- 注意变量 `price`、`quantity` 和 `discount` 都是 `int` 类型,但折扣计算中 `(100 - discount)` 是整数运算,可能导致精度丢失。虽然除以 `100.0` 会转为浮点,但整数乘法可能先溢出(如果数值较大)。
- 检查 `scanf` 的格式:三个 `%d` 之间没有分隔符,输入时需要用空格或换行分隔数字,这是正确的。但输出格式中 `C=%.2f` 后面多了一个空格,可能不是题目要求。