用C语言编写以下代码:某商场推出打折促销活动:若顾客购物额不满 100 元则不优惠;达到或超过 100 元则九五折优惠;达到或超过 200 元则九折优惠;达到或超过 500 元则八五折优惠;达到或超过 1000 元则八折优惠。请编写程序,根据购物金额计算优惠后的实际付款金额。
时间: 2023-05-27 18:06:43 浏览: 144
```c
#include <stdio.h>
int main() {
float amount, discount, payable;
printf("请输入购物金额:");
scanf("%f", &amount);
if (amount < 100) {
discount = 0;
} else if (amount < 200) {
discount = 0.05;
} else if (amount < 500) {
discount = 0.1;
} else if (amount < 1000) {
discount = 0.15;
} else {
discount = 0.2;
}
payable = amount * (1 - discount);
printf("优惠后的实际付款金额为:%.2f元\n", payable);
return 0;
}
```
相关问题
使用C语言写以下代码某商场推出打折促销活动:若顾客购物额不满 100 元则不优惠;达到或超过 100 元则九五折优惠;达到或超过 200 元则九折优惠;达到或超过 500 元则八五折优惠;达到或超过 1000 元则八折优惠。请编写程序,根据购物金额计算优惠后的实际付款金额。
```C
#include <stdio.h>
int main()
{
float total; //购物总金额
float discount = 1.0; //默认优惠无打折,打折系数为1.0
float pay; //应付金额
printf("请输入购物总金额:");
scanf("%f", &total);
if (total >= 100 && total < 200)
{
discount = 0.95; //九五折
}
else if (total >= 200 && total < 500)
{
discount = 0.9; //九折
}
else if (total >= 500 && total < 1000)
{
discount = 0.85; //八五折
}
else if (total >= 1000)
{
discount = 0.8; //八折
}
pay = total * discount;
printf("应付款金额:%.2f元", pay);
return 0;
}
```
使用C语言编写一个代码:使用指针的方法求100以内的素数
好的,下面是使用指针的C语言代码实现:
```
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
int main() {
bool* isPrime = (bool*)malloc(sizeof(bool) * 100);
int i, j;
for (i = 2; i < 100; i++) {
*(isPrime + i) = true;
}
for (i = 2; i <= sqrt(100); i++) {
if (*(isPrime + i)) {
for (j = i * i; j < 100; j += i) {
*(isPrime + j) = false;
}
}
}
for (i = 2; i < 100; i++) {
if (*(isPrime + i)) {
printf("%d ", i);
}
}
free(isPrime);
return 0;
}
```
该代码的思路与上一个回答基本一致,只不过使用了指针来访问数组元素。
相关推荐
![](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)