#include<stdio.h>double fun(double x);main(){double a,b;scanf("%f",&a);b=fun(a);printf("%f\n",b);}double fun(double x){double y;if (x<-1)y=x*x-1;elseif (x<=1)y=x*x;elsey=x*x+1;return(y);}
3 回答
波斯汪
TA贡献1811条经验 获得超4个赞
scan()函数中:%f对应是float类型,%lf对应的是 double类型
printf()函数中:%f即对应float类型也对应double类型
#include<stdio.h>
double fun(double x);
main()
{
double a,b;
scanf("%lf",&a);
b=fun(a);
printf("%f\n",b);
}
double fun(double x)
{
double y;
if (x<-1)
y=x*x-1;
else
if (x<=1)
y=x*x;
else
y=x*x+1;
return(y);
}
结果:
输入:10
显示:101
添加回答
举报
0/150
提交
取消