A. 用c語言編寫一個衣服打折的程序,一件打九折,兩件七點五折,三件或三件以上五折,有會的的神嗎,求指導
#include<stdio.h>
intmain()
{
intx;
floatprice,money;
printf("請輸入購買件數:");
scanf("%d",&x);
printf("請輸入單價:");
scanf("%f",&price);
if(x==1)
money=0.9*price;
elseif(x==2)
money=0.75*2*price;
elseif(x>=3)
money=0.5*x*price;
printf("打折後總金額是:%f",money);
return0;
}
敲代碼不容易,望採納。對了臨時寫的有可能會有中文字元,稍微注意下,有問題請追問
B. C語言題:輸入一個購物金額求輸出折扣率與付款金額,如圖
#include<stdio.h>
intmain()
{
inti;floatpay;
scanf("%f",&pay);
if(pay<=0)printf("輸入購物金額有誤!");
else
{
if(pay<200)i=10;
elseif(pay<500)i=9;
elseif(pay<1000)i=8;
elsei=7;
i/10?printf("不打折,"):printf("折扣率:%d折,",i);
printf("實際付款金額:%.2f元",pay*i/10);
}
return0;
}
C. c語言編寫商品打折程序,如圖所示,急急急急急
1)
#include"stdio.h"
intmain(intargc,char*argv[]){
doublem,r;
printf("請輸入商品的價格: ");
if(scanf("%lf",&m)!=1||m<=0){
printf("輸入錯誤,退出...... ");
return0;
}
printf("請輸入折扣率: ");
if(scanf("%lf",&r)!=1||r<=0||r>=1){
printf("輸入錯誤,退出...... ");
return0;
}
printf("商品價格:%.2f元,折扣:%.2f,折扣後份額:%.2f元 ",m,r,m*r);
return0;
}
運行樣例:
D. C語言題目,使用SWITCH語句計算折扣率。
#include <stdio.h>
int main()
{
double je,zk;
int x;
printf("那個輸入金額(大於0):");
scanf("%lf",&je);
x=(int)(je/100);
switch(x)
{
case 0:case 1:case 2:zk=je;break;
case 3:case 4:zk=je*0.9;break;
case 5:case 6:case 7:zk=je*0.7;break;
default:zk=je*0.5;
}
printf("折扣率為:%f,實際支付金額:%f\n",zk/je,zk);
return 0;
}
E. 買書打折用C語言怎麼編程
輸入原價
根據打折幅度, 輸出實際售價
如果根據原價有多個打折幅度,那麼就用if else
比較簡單的,比如固定打8折,那麼就是
intmain()
{
doubler;
scanf("%lf",&r);
r*=0.8;
printf("%lf ",r);
}
F. 用C語言編寫一個程序,要求輸入購買商品的錢款數,輸出相應的折扣率
你這個題目無法實現的,因為折扣率應該是在知道原價的基礎上的。目前給出條件不足。
這里做個假設:
如果輸入是兩個,折扣前和折扣的,那麼可以計算,比如:
float beforePayment,afterPayment;
float percentage;
scanf("折扣前金額=%f",&beforePayment);
scanf("折扣後金額=%f",&afterPayment);
percentage=afterPayment/beforePayment;
printf("產品折扣率為:%.2f",percentage);//保留兩位小數進行顯示
G. C語言求 ②某商場給出的購物折扣率如下: 購物金額<100元,不打折; 100元≦購物金額<30
#include <stdio.h>
int main(void)
{ float cost;
float discount,pay;
printf("請輸入購物金額:");
scanf("%f",&cost);
if(cost>=0)//購物金額大於等於0
{
if(cost>=0&&cost<100)//購物金額為小於100
discount=1;
else if(cost>=100&&cost<300)//購物金額大於等於100小於300
discount=0.9;
else if(cost>=300&&cost<500)//購物金額大於等於300小於500
discount=0.8;
else //購物金額大於等於500
discount=0.75;
pay=cost*discount;
printf("當購物金額是%.2f,折扣為%.2f,實際付款%.2f\n",cost,discount,pay);
/**************************switch語句實現****************************************/
printf("使用switch語句:\n");
int num=cost/100;//對cost/100取整(例如cost=150,num=1)確定所在的區間范圍
switch(num){
case 0: discount=1;break;//購物金額為小於100
case 1: discount=0.9;break;
case 2: discount=0.9;break;//case 1,2為購物金額大於等於100小於300
case 3: discount=0.8;break;
case 4: discount=0.8;break;//case 3,4為購物金額大於等於300小於500
default: //購物金額大於等於00
discount=0.75;break;}
pay=cost*discount;
printf("當購物金額是%.2f,折扣為%.2f,實際付款%.2f\n",cost,discount,pay);}
else //購物金額小於0
printf("輸入有誤,cost必須滿足大於等於0");
return 0;
}
H. c語言超市優惠活動規定所夠物品不超過100元時,按9折付款,超過100元,按8折付款
要做什麼?
#include<stdio.h>
intmain(){
floatx,y;
scanf("%f",&x);
if(x<=100)
y=x*0.9;
else
y=x*0.8;
printf("%f ",y);
return0;
}
這樣??
I. 用C語言寫一個打折程序.如圖所示
#include<stdio.h>
intmain()
{
intx;
floaty;
printf("請輸入本次消費的金額: ");
scanf("%d",&x);
if(x>=1000)
y=x*0.85;
elseif(500<=x&&x<1000)
y=0.9*x;
elseif(300<=x&&x<500)
y=0.96*x;
elseif(x<300&&x>0)
y=x;
printf("實際花費的金額:%.2f",y);
return0;
}