1. c语言if else语句是什么
c语言if else语句是:if和else是c语言中两个关键的函数,if意思为如果,else意思为否则,主要是用来对条件进行判断,并根据判断结果执行不同的语句,if一般在if else语句中充当判断条件,else是两个语句的连接词,从而组成if else语句。
if else语句的编辑方法:首先选择一个c语言编辑器,定义一个变量height,并且进行赋值,在下边写上if条件,然后在把不同结果的意思用else连接起来,最后点击编辑运行,从而就能看到编辑的结果。
c语言常用的语句有:if语句,else语句,switch语句,goto语句,while语句,do…while语句,for语句,break语句,continue语句等;常用的函数有:putchar函数,getchar函数,printf函数,scanf函数等。
2. 用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;
}
敲代码不容易,望采纳。对了临时写的有可能会有中文字符,稍微注意下,有问题请追问
3. c语言编程、商场促销、男的不打折、女的打折、怎么编
int after_money(int money)
{
if (money < 400)
return money;
else if (money < 800)
return (money*0.95);
else if (money < 1200)
return (money*0.925);
else if (money < 1600)
return (money*0.9);
else if (money < 2000)
return (money*0.88);
else
return (money*0.85);
}
4. 用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;
}
5. C语言的折扣计算问题 用代码来编
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void input(){
double rate=0.045,money;
char s[]="",temp[100];
printf("请输入产品价格:");
scanf("%lf",&money);
double b = money-(int)money;//提取出小数部分
gcvt(b,7,s); //将小数部分转换成字符串数组为后面判断有几个数字准备的
sprintf(temp,"%lf",b); //将小数部分依次存入字符串数组
int count=0; //存放有几位小数
int i;
for(i=2;i<=strlen(s);i++){//从2开始,因为下标0存放是字符0,下标1存放的是小数点
count++;
}
if(money<=0){
printf("产品价格必须大于0!\n");
input();
/**如果十分位是0,则字符串长度必须减去4,
如果十分不是0,则字符串长度必须减去1,
因为字符串自动在末尾补0了*/
}else if(((int)temp[2]==48&&count-4!=2)||((int)temp[2]!=48&&count-1!=2)){
printf("产品价格必须是两位小数!\n");
input();
}else{
if(money<=1000){
printf("您的消费还不满足折扣要求,应付金额为:%.2f米,您只需再消费%.2f,就可以享受折扣\n",money,(1000.01-money));
}else{
printf("您可以享受折扣,应付的金额为:%.2f米\n",(100-rate)*money);
}
}
}
void main(){
input();
}
6. 求C语言大神编一个程序(分别用switch和if-else结构)某商店推出打折活动,要求购物达到或超过2000元的
doublen=0;
scanf("%lf",&n);
boolr1=n>=2000;
boolr2=n>=1000;
boolr3=n>=500;
switch(r1+r2+r3){
case0:
printf("%.2f",n);
break;
case1:
printf("%.2f",n-50);
break;
case2:
printf("%.2f",n*0.85);
break;
case3:
printf("%.2f",n*0.8);
break;
}
if(r3==0){
printf("%.2f",n);
elseif(r2==0)
printf("%.2f",n-50);
elseif(r1==0)
printf("%.2f",n*0.85);
else
printf("%.2f",n*0.8);
}
7. 买书打折用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 运行情况
8. 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;
}
运行样例:
9. 用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;
}
}
10. 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的不减,
当然 如果你是做题 的话 请严格按照题意