#include<stdio.h> int main(void) { int i,n; double x,y; printf("enter n:"); scanf("%d",&n); for(i=1;i<=n;i++){ printf("Enter x:\n"); scanf("%lf",&x); if (x<=0){ printf("wrong\n"); } else if(x<=50){ y=x*0.53; } else{ y=x*0.53+(x-50)*0.58; } printf("f%.0f=%.0f\n",x,y); } return 0; }
/计算圆柱体积/
#include<stdio.h> int main() { int i,n; double r,v,h; double cylinder(double r,double h); /函数声明/ printf("enter n:"); scanf("%d",&n); for(i=1;i<=n;i++){ printf("Enter r and h:\n"); scanf("%lf%lf",&r,&h); if((r<=0)||(h<=0)) { printf("输入错误,重新输入"); } else{ v=cylinder(r,h); /调用函数,返回值赋给volume/
printf("V=%.3f\n",v); } } return 0; } double cylinder(double r,double h) { double result; result=3.1415926*r*r*h; /计算圆柱体积/
return result; /返回结果/
}
/计算电价/ #include<stdio.h> int main(void) { int i; double y; printf("enter i(i>0):"); scanf("%d",&i); if(i<50){ y=0.53*i; } else if(i>50){ y=0.53*i+(i-50)*0.58; } printf("y=%.2f\n",y); return 0; }