当前位置:首页 » 编程语言 » c语言打折怎么写
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言打折怎么写

发布时间: 2022-09-15 09:23:33

Ⅰ 用c语言编一个计算衣服价格的程序,要求一件衣服打九折,两件衣服7.8折,三件打五折,大于三件还是打

#include<stdio.h>
void calc(double prirce,int num){
double total;
if(num==1){
total = prirce*0.9;
}else if(num==2){
total = num*prirce*0.78;
}else{
total=num*prirce*0.5;
}
printf("你买了%d件衣服,衣服的总价格是%2f",num,total);
}
void main(){
double inputPrice[3]={41.56,782.4,87.93};
calc(inputPrice[0],2);
calc(inputPrice[1],3);
calc(inputPrice[2],1);
}

Ⅱ C语言问题求大神请教 某商店推出打折活动,要求购物达到或超过2000元得打八折,购物达到或超过5

int ShoudPay(int value)
{
if(value < 500)
return value;
else if(value >=500 && value < 2000)
return value - 50;
else
return (int )(value * 0.8f);
}
原文没有提到 1000 - 2000,不科学。不可能500 - 1000的都减价,1000 - 2000的不减,
当然 如果你是做题 的话 请严格按照题意

Ⅲ 用C语言写一个打折程序.如图所示

#include "stdio.h"
int main()
{ double a,b; //a 表示花的钱数,b表示打折后的钱数
scanf("%lf",&a);//输入你要花的钱数
if(a>=1000) b=0.85*a;
else
if(a>=500&&a<1000) b=0.9*a;
else
if(a>=300&&a<500) b=0.95*a;
else b=a;
printf("输出实际花的钱数%lf",b);
}

Ⅳ 用C语言编写一个程序,要求输入购买商品的钱款数,输出相应的折扣率

你这个题目无法实现的,因为折扣率应该是在知道原价的基础上的。目前给出条件不足。
这里做个假设:
如果输入是两个,折扣前和折扣的,那么可以计算,比如:
float beforePayment,afterPayment;
float percentage;
scanf("折扣前金额=%f",&beforePayment);
scanf("折扣后金额=%f",&afterPayment);
percentage=afterPayment/beforePayment;
printf("产品折扣率为:%.2f",percentage);//保留两位小数进行显示

Ⅳ c语言 输入在一行中给出商品的原价和折扣,在一行中输出商品的折扣价,保留小数点后 2 位

代码的错误在于,你的代码中scanf函数那一行,表述第一个参数yj的格式字符串少打了一个%,正确的代码应该是:scanf(“%d %d”,&yj,&zk);

Ⅵ c语言入门折扣编程

  • #include<stdio.h>
    int main(void)
    {
    while(1)
    {
    printf(" 请输入商品价格,无商品时请输入负数! ");
    float price = 0;
    float sum = 0;
    while(1)
    {
    scanf("%f",&price);
    if(price < 0) break;
    sum += price;
    }
    if(sum > 1000)
    {
    printf("您可以享受折扣,应付的金额为%.2f元。 ",sum*0.955);
    }
    else
    {
    printf("您的消费还不满足折扣要求,应付的金额为%.2f元;您只需再消费%.2f元就可以享受折扣! ",sum,1000-sum);
    }
    }
    return 0;
    }

Ⅶ 用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;
}

敲代码不容易,望采纳。对了临时写的有可能会有中文字符,稍微注意下,有问题请追问

Ⅷ 用c语言 if结构来回答.普通顾客购物满100元 享受9折优惠。会员购物满200

先分析

如果是普通客户:

那么当购物的价格满100元则打折9折;最后的付款将是购物价的90%;

如果是会员:

那么当购物价格满200元则打折7.5,不满的打折8,所以最终付款需要根据购物价来打折。

代码判断如下:

intsalePrice=N;//购物的价格
floatpayPrice;//最后的付款金额
boolisVIP=true/false;//是否是会员
if(isVIP)
{
if(salePrice>=100)
{
payPrice=salePrice*0.9;
}
else
{
payPrice=salePrice;
}
}
else
{
if(salePrice>200)
{
payPrice=salePrice*0.75;
}
else
{
payPrice=salePrice*0.8;
}
}

Ⅸ 买书打折用C语言怎么编程

1 涉及的C语言知识

(1)输入

(2)加减乘除运算

(3)输出

2 一个小示例

#include<stdio.h>

floatget_discount(intx){
floatoutput=0;

//当输入以0结尾时,不合法,返回0
if(x%10==0)
returnoutput;

//当输入为85时,代表85折,输出应为0.85
if(x>10&&x<100)
output=x/100.0;

//当输入为7时,代表7折,输出应为0.7
if(x<10&&x>=1)
output=x/10.0;

returnoutput;
}
intmain(){
floatcount;
intdiscount_str;

puts("输入书的金额和打印情况(以空格为分割符,按回车结束):");
puts("(如输入的是207则表示20元的书打7折)");

scanf("%f%d",&count,&discount_str);

floatdiscount_f=get_discount(discount_str);
if(discount_f==0)
puts("输入的打折情况不合法.");
else{
floatresult=count*discount_f;
printf("打折后的金额为:%.2f ",result);
}
getchar();
getchar();
return0;
}

3 运行情况

Ⅹ 用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;
}