#include
#include
int main(void)
{
int input_area;
float weigh,price = 0;
int area_start_money[5] = {10,10,15,15,15};
int area_extra_money[5] = {3,4,5,6.5,10};
int area_lenth[2] = {0,5};
printf("Please input area number and weigh(eg:0,10.5):\n");
scanf("%d,%f",&input_area,&weigh);
if(input_area < area_lenth[0] || input_area > area_lenth[1] )
printf("Error in Area\n");
else
{
weigh -= 1;
price += area_start_money[input_area];
price += weigh > 0 ? ceil(weigh)*area_extra_money[input_area] : 0;
printf("Price: %5.2f\n",price);
}
return 0;
}
#include
#include
main(){
int area,w,flag=1;
float price,weight;
scanf("%d,%f",&area,&weight);
w=(int)weight+1;
switch(area){
case 0: price=10+3*(w-1);break;
case 1: price=10+4*(w-1);break;
case 2: price=15+5*(w-1);break;
case 3: price=15+6.5*(w-1);break;
case 4: price=15+10*(w-1);break;
default:{
printf("Error in Area\n");
printf("Price: 0.00\n");
flag=0;
}
}
if(flag)
printf("Price: %5.2f\n",price);
system("pause");
}
while(s[i]!='0')i++;
应该改为while(s[i]!='\0')i++;
注意字符串结束符号为'\0',不是'0'
#include
int main()
{ int n,i,j,t,a[100];
scanf("%d",&n);
for(i=0; i scanf("%d",&a[i]); for(i=0,j=n-1; i { t=a[i]; a[i]=a[j]; a[j]=t; } for(i=0; i printf("%d ",a[i]); return 0; }
#include
int main()
{
float cost,realCost;
printf("顾客购买图书的总金额: ");
scanf("%f",&cost);
if(cost<=0.0)
{
printf("Input Error!");
return -1;
}
else if(cost<100)
realCost=cost;
else if(cost >=100 && cost < 200)
realCost=cost-30;
else if(cost >= 200 && cost < 300)
realCost=cost-60;
else
realCost=cost-100;
printf("优惠后的付款金额为: %.2f\n",realCost);
return 0;
}
示例运行结果:
顾客购买图书的总金额: 250
优惠后的付款金额为: 190.00
顾客购买图书的总金额: 88
优惠后的付款金额为: 88.00
顾客购买图书的总金额: 300
优惠后的付款金额为: 200.00