"#include <stdio.h>\n\nint main() {\n int originalPrice, discount; \n \n // 获取用户输入的原始价格和折扣\n scanf("%d %d", &originalPrice, &discount);\n \n // 计算折扣后的价格\n double discountedPrice = originalPrice * discount / 10.0; \n \n // 输出折扣后的价格,保留两位小数\n printf("%.2lf\n", discountedPrice);\n \n return 0; \n}\n\n注释解释:\n\n1. `#include <stdio.h>`:包含标准输入输出库的头文件。\n\n2. `int main()`:程序的入口函数。\n\n3. `int originalPrice, discount; `:声明两个整型变量originalPrice和discount,用于存储原始价格和折扣。\n\n4. `scanf("%d %d", &originalPrice, &discount);`:从用户输入中获取原始价格和折扣的值,并将其存储在originalPrice和discount变量中。\n\n5. `double discountedPrice = originalPrice * discount / 10.0; `:根据原始价格和折扣计算折扣后的价格,并将结果存储在discountedPrice变量中。注意,除以10.0而不是10,是为了得到折扣的小数形式。\n\n6. `printf("%.2lf\n", discountedPrice);`:将折扣后的价格输出到屏幕上,并保留两位小数。\n\n7. `return 0; `:返回0,表示程序成功执行结束。

C语言程序:计算商品折扣价格

原文地址: https://www.cveoy.top/t/topic/qd8C 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录