本文目錄一覽:
- 1、C語言題:輸入一個購物金額求輸出折扣率與付款金額,如圖
- 2、編寫c語言程序,輸入購物款數,計算並輸出優惠價。(要求用switch語句編寫)
- 3、c語言 如何用switch語句編寫一個有關商場購物金額優惠的選擇程序
- 4、c語言中輸入一個顧客的購物款後,顯示它應付的款數?
- 5、用C語言編寫一個程序,要求輸入購買商品的錢款數,輸出相應的折扣率?
C語言題:輸入一個購物金額求輸出折扣率與付款金額,如圖
#include stdio.h
int main()
{
int i;float pay;
scanf(“%f”,pay);
if(pay=0) printf(“輸入購物金額有誤!”);
else
{
if(pay200) i=10;
else if(pay500) i=9;
else if(pay1000) i=8;
else i=7;
i/10?printf(“不打折,”):printf(“折扣率:%d折,”,i);
printf(“實際付款金額:%.2f元”,pay*i/10);
}
return 0;
}
編寫c語言程序,輸入購物款數,計算並輸出優惠價。(要求用switch語句編寫)
#include stdio.h
int main()
{
float totalprice=0,level=0; //總的消費額,打折等級標誌
scanf(“%d”,totalprice);
if(totalprice=1000) level=1; //一共分為五等,不同等級,對應不同的優惠策略。
else if(totalprice1000 totalprice=2000) level=2;
else if(totalprice2000 totalprice=3000) level=3;
else if(totalprice3000 totalprice=5000) level=4;
else level=5;
switch(level) //一共分為五等,不同等級,對應不同的優惠策略。
{
case 1: printf(“%f”,totalprice);break;
case 2: printf(“%f”,totalprice*0.95);break;
case 3: printf(“%f”,totalprice*0.90);break;
case 4: printf(“%f”,totalprice*0.85);break;
default: printf(“%f”,totalprice*0.80);break;
}
return 0;
}
c語言 如何用switch語句編寫一個有關商場購物金額優惠的選擇程序
#include stdio.h
int main(int argc, char** argv)
{
int amount = 0;
scanf(“%d”, amount);//輸入顧客購買的總額
int status = amount/1000;
switch (status)
{
case 0: break;
case 1: amount = amount * 0.95; break;
case 2: amount = amount*0.90; break;
case 3: amount *= 0.85; break;
default: amount *= 0.80; break;
}
printf(“%d\n”, amount);//打印出打折後的總額
return 0;
}
c語言中輸入一個顧客的購物款後,顯示它應付的款數?
現在都什麼時候了,還學c語言,覺得這個沒前途,而且學了頭疼。
用C語言編寫一個程序,要求輸入購買商品的錢款數,輸出相應的折扣率?
你這個題目無法實現的,因為折扣率應該是在知道原價的基礎上的。目前給出條件不足。
這裡做個假設:
如果輸入是兩個,折扣前和折扣的,那麼可以計算,比如:
float beforePayment,afterPayment;
float percentage;
scanf(“折扣前金額=%f”,beforePayment);
scanf(“折扣後金額=%f”,afterPayment);
percentage=afterPayment/beforePayment;
printf(“產品折扣率為:%.2f”,percentage);//保留兩位小數進行顯示
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/160038.html