c语言写某商品出售按购买数量打折,如果购买数量超过60个则按6折销售,51到60之间按7折销售,41到50之间按8折销售,31到40之间按9折销售。30及以下按原价出售,输入商品数量和商品单价(元),输出所购商品的总价。
时间: 2023-05-13 15:07:05 浏览: 394
以下是 C 语言代码:
```
#include <stdio.h>
int main() {
int quantity;
float price, total;
printf("请输入商品数量和单价(用空格隔开):");
scanf("%d %f", &quantity, &price);
if (quantity > 60) {
total = quantity * price * 0.6;
} else if (quantity >= 51 && quantity <= 60) {
total = quantity * price * 0.7;
} else if (quantity >= 41 && quantity <= 50) {
total = quantity * price * 0.8;
} else if (quantity >= 31 && quantity <= 40) {
total = quantity * price * 0.9;
} else {
total = quantity * price;
}
printf("所购商品的总价为:%.2f元\n", total);
return 0;
}
```
相关问题
c语言写某商品出售按购买数量打折,如果购买数量超过30个则按95折销售,输入商品数量和商品单价(元),输出所购商品的总价
好的,以下是C语言的代码:
```c
#include <stdio.h>
int main() {
int quantity;
float price, total;
printf("请输入商品数量:");
scanf("%d", &quantity);
printf("请输入商品单价(元):");
scanf("%f", &price);
if (quantity > 30) {
total = quantity * price * 0.95;
} else {
total = quantity * price;
}
printf("所购商品的总价为:%.2f元\n", total);
return 0;
}
```
希望能对您有所帮助!
c语言⑴某商品出售按购买数量打折,如果购买数量超过30个则按95折销售,输入商品数量和商品单价(元),输出所购商品的总价
好的,根据您的描述,我可以为您提供以下的 C 语言代码:
```c
#include <stdio.h>
int main() {
int quantity;
float price, total;
printf("请输入商品数量:");
scanf("%d", &quantity);
printf("请输入商品单价(元):");
scanf("%f", &price);
if (quantity > 30) {
total = quantity * price * 0.95;
} else {
total = quantity * price;
}
printf("所购商品的总价为:%.2f 元\n", total);
return 0;
}
```
您可以将以上代码复制到 C 语言的开发环境中进行编译和运行,然后根据提示输入商品数量和商品单价,程序将会输出所购商品的总价。希望这可以帮助到您!
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)