# C语言--第四周作业

1.代码

#include <stdio.h>
int main ()
{
float x,result;
scanf("%f",&x);
if(x==0)
{
result = 0;
}
else
{
result = 1/x;
}
printf("f(%.1f) = %.1f",x,result);
}


2.设计思路
(a)

(b)流程图

3.错误

1.代码

#include <stdio.h>
int main()
{
int x,y;
float c;
scanf("%d %d",&x,&y);
if (y==0)
{
printf("%d/%d=Error",x,y);
}
else if(y<0)
{
c = 1.0*x/y;
printf("%d/(%d)=%.2f",x,y,c);
}
else
{
c = 1.0*x/y;
printf("%d/%d=%.2f",x,y,c);
}
return 0;
}


2.思路
(a)步骤

(b)

3.错误

1.代码

#include <stdio.h>
int main ()
{
float x,cost;
scanf("%f",&x);
if(x<=50)
{
if(x<0)
{
printf("Invalid Value!\n");
}
else
{
cost = x*0.53;
printf("cost = %.2f",cost);
}
}

else
{
cost = 50*0.53+(x-50)*0.58;
printf("cost = %.2f",cost);
}
}


2.思路
(a)

(b)

1.代码


#include <stdio.h>
int main()
{
float a,b;
int x;
scanf("%f %d",&a,&x);
if(a<=3)
{
x = 10+b/5*2;
printf("%.0f",x);
}
else if(a>3&&a<=10)
{
x = 10+2*(a-3)+b/5*2;
printf("%.0f",x);
}
else
{
x = 10+2*7+(a-10)*2*1.5+b/5*2;
printf("%.0f",x);
}
}


2.思路
(a)

(b)流程图

3.错误

Git地址：https://git.coding.net/GUANCHENG/TRY.git

posted @ 2017-10-29 00:45  顾安城  阅读(272)  评论(7编辑  收藏  举报