计算s=#(f(-0.1)+f(5.0))的值
答案:1 悬赏:40 手机版
解决时间 2021-12-01 07:31
- 提问者网友:疯孩纸
- 2021-11-30 23:55
计算s=#(f(-0.1)+f(5.0))的值
最佳答案
- 五星知识达人网友:蓝房子
- 2021-12-01 00:23
#include
float f(int x)//函数带返回值,float类型,
{
int a,b,c;
float fx;//返回值
a=x+1;
b=x-2;
c=x-1;//c赋值错误
if (x>=1)
fx=1.0*a/b;//乘上1.0防止数据精度丢失
if(x==0||x==2)//逻辑运算,不是赋值
fx=0;
if(x<0)
fx=1.0*c/b;
return fx;//返回值
}
void main()
{
int x;
float s;//定义变量存函数和
//f(int n);//在主函数前不用声明
for(x=-30;x<=30;x++)
{
s+=f(x);//调用函数f求和
}
printf("s=%f",s);//打印各个函数的求和值
}
float f(int x)//函数带返回值,float类型,
{
int a,b,c;
float fx;//返回值
a=x+1;
b=x-2;
c=x-1;//c赋值错误
if (x>=1)
fx=1.0*a/b;//乘上1.0防止数据精度丢失
if(x==0||x==2)//逻辑运算,不是赋值
fx=0;
if(x<0)
fx=1.0*c/b;
return fx;//返回值
}
void main()
{
int x;
float s;//定义变量存函数和
//f(int n);//在主函数前不用声明
for(x=-30;x<=30;x++)
{
s+=f(x);//调用函数f求和
}
printf("s=%f",s);//打印各个函数的求和值
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯