第一关 快递费用计算
#include<stdio.h>
int main(void)
{
/*********Begin*********/
int area,b;
float weight,price;
scanf("%d,%f",&area,&weight);
if(weight-(int)weight==0)
{
b=(int)weight;
}
else{
b=(int)weight+1;
}
switch(area){
case 0:
price=10+(b-1)*3;
printf("Price: %.2f\n",price);
break;
case 1:
price=10+(b-1)*4;
printf("Price: %.2f\n",price);
break;
case 2:
price=15+(b-1)*5;
printf("Price: %.2f\n",price);
break;
case 3:
price=15+(b-1)*6.5;
printf("Price: %.2f\n",price);
break;
case 4:
price=15+(b-1)*10;
printf("Price: %.2f\n",price);
break;
default:
printf("Error in Area\nPrice: 0.00\n");
}
/*********End**********/
return 0;
}
第二关 计算一元二次方程的根
#include<stdio.h>
int main(void)
{
/*********Begin*********/
float a,b,c,x1,x2,d;
printf("Please enter the coefficients a,b,c:\n");
scanf("%f,%f,%f",&a,&b,&c);
d=sqrt(b*b-4*a*c);
if(d>=0){
x1=(-b+d)/(2*a);
x2=(-b-d)/(2*a);
printf("x1=%.4f, x2=%.4f\n",x1,x2);
}
else{
printf("error!\n");
}
/*********End**********/
return 0;
}
第三关 产品信息格式化
#include<stdio.h>
int main(void)
{
/*********Begin*********/
int number,year,month,day;
float price;
printf("Enter item number:\n");
scanf("%d",&number);
printf("Enter unit price:\n");
scanf("%f",&price);
printf("Enter purchase date (mm/dd/yy):\n");
scanf("%d/%d/%d",&month,&day,&year);
printf("Item Unit Purchase\n");
printf("%-9d$ %-9.2f%02d%02d%02d\n",number,price,month,day,year);
/*********End**********/
return 0;
}