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