C语言在区间[0,1]内用二分法求方程e^x+10x-2=0的近似根,误差不超过0.5*10^(-3),#include #include #include #include float getvalue(float x) {return e^x+10x-2; } int main() {float a=0,b=1,c; c=(a+b)/2; while(fabs(getvalue(c))>0.5*10^(-
来源:学生作业帮助网 编辑:作业帮 时间:2024/08/28 09:10:19
![C语言在区间[0,1]内用二分法求方程e^x+10x-2=0的近似根,误差不超过0.5*10^(-3),#include #include #include #include float getvalue(float x) {return e^x+10x-2; } int main() {float a=0,b=1,c; c=(a+b)/2; while(fabs(getvalue(c))>0.5*10^(-](/uploads/image/z/2693520-0-0.jpg?t=C%E8%AF%AD%E8%A8%80%E5%9C%A8%E5%8C%BA%E9%97%B4%5B0%2C1%5D%E5%86%85%E7%94%A8%E4%BA%8C%E5%88%86%E6%B3%95%E6%B1%82%E6%96%B9%E7%A8%8Be%5Ex%2B10x-2%3D0%E7%9A%84%E8%BF%91%E4%BC%BC%E6%A0%B9%2C%E8%AF%AF%E5%B7%AE%E4%B8%8D%E8%B6%85%E8%BF%870.5%2A10%5E%28-3%29%2C%23include+%23include+%23include+%23include+float+getvalue%28float+x%29+%7Breturn+e%5Ex%2B10x-2%3B+%7D+int+main%28%29+%7Bfloat+a%3D0%2Cb%3D1%2Cc%3B+c%3D%28a%2Bb%29%2F2%3B+while%28fabs%28getvalue%28c%29%29%3E0.5%2A10%5E%28-)
C语言在区间[0,1]内用二分法求方程e^x+10x-2=0的近似根,误差不超过0.5*10^(-3),#include #include #include #include float getvalue(float x) {return e^x+10x-2; } int main() {float a=0,b=1,c; c=(a+b)/2; while(fabs(getvalue(c))>0.5*10^(-
C语言在区间[0,1]内用二分法求方程e^x+10x-2=0的近似根,误差不超过0.5*10^(-3),
#include
#include
#include
#include
float getvalue(float x)
{
return e^x+10x-2;
}
int main()
{
float a=0,b=1,c;
c=(a+b)/2;
while(fabs(getvalue(c))>0.5*10^(-3) && fabs(a-b)>0.5*10^(-3))
{
if(getvalue(c)*getvalue(b)
C语言在区间[0,1]内用二分法求方程e^x+10x-2=0的近似根,误差不超过0.5*10^(-3),#include #include #include #include float getvalue(float x) {return e^x+10x-2; } int main() {float a=0,b=1,c; c=(a+b)/2; while(fabs(getvalue(c))>0.5*10^(-
首先,你的手写格式和编程语言格式是不一致的.然后,你使用的自然对数底数e,也没有定义.其他的都是小问题.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define e 2.7182828//定义自然对数底数的值
float getvalue(float x)
{
return pow(e,x)+10*x-2;
}
int main()
{
float a=0,b=1,c;
c=(a+b)/2;
while(fabs(getvalue(c))>0.5*1e-3)//此处可以简单化
{
if(getvalue(c)*getvalue(b)<0)
a=c;
if(getvalue(a)*getvalue(c)<0)
b=c;
c=(a+b)/2;
}
printf("%0.3f\n",c);
return 0;
}
我这边算出来的结果是0.091.