c语言程序编写某商品出售按购买数量打折,如果购买数量超过60个则按6折销售,51到60之间按7折销售,41到50之间按8折销售,31到40之间按9折销售。30及以下按原价出售,输入商品数量和商品单价(元),输出所购商品的总价。
时间: 2023-05-21 20:05:42 浏览: 51
以下是求解此问题的C语言程序:
```
#include <stdio.h>
int main()
{
int quantity;
float unit_price, total_price;
printf("请输入商品数量和商品单价(元),用空格分隔:");
scanf("%d%f", &quantity, &unit_price);
if (quantity > 60) {
total_price = quantity * unit_price * 0.6;
} else if (quantity >= 51) {
total_price = quantity * unit_price * 0.7;
} else if (quantity >= 41) {
total_price = quantity * unit_price * 0.8;
} else if (quantity >= 31) {
total_price = quantity * unit_price * 0.9;
} else {
total_price = quantity * unit_price;
}
printf("所购商品总价为:%.2f元\n", total_price);
return 0;
}
```
相关问题
C语言程序设计某商品出售按购买数量打折,如果购买数量超过60个则按6折销售,51到60之间按7折销售,41到50之间按8折销售,31到40之间按9折销售。30及以下按原价出售,输入商品数量和商品单价(元),输出所购商品的总价。
以下是C语言程序设计的代码:
```c
#include <stdio.h>
int main() {
int quantity;
float price, total_price;
printf("请输入商品数量和单价(用空格隔开):");
scanf("%d %f", &quantity, &price);
if (quantity > 60) {
total_price = quantity * price * 0.6;
} else if (quantity >= 51) {
total_price = quantity * price * 0.7;
} else if (quantity >= 41) {
total_price = quantity * price * 0.8;
} else if (quantity >= 31) {
total_price = quantity * price * 0.9;
} else {
total_price = quantity * price;
}
printf("所购商品的总价为:%.2f元\n", total_price);
return 0;
}
```
如果输入的商品数量为70,单价为10元,则输出的结果为:
```
请输入商品数量和单价(用空格隔开):70 10
所购商品的总价为:420.00元
```
如果输入的商品数量为20,单价为5元,则输出的结果为:
```
请输入商品数量和单价(用空格隔开):20 5
所购商品的总价为:100.00元
```
希望能够帮助到您!
某商品出售按购买数量打折,如果购买数量超过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;
}
```
这段代码会先让用户输入商品数量和单价,然后根据购买数量是否超过30个来计算总价。如果超过30个,则按95折计算,否则按原价计算。最后输出所购商品的总价。希望这个答案能够帮到你!
相关推荐
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)