标签:code class using div else mat bsp double name
求下面方程的 一个根: 根:f(x) = x 3 -5x 2 +10x-80 = 0。若求出的根是 若求出的根是a ,则要求 |f(a)| <= 10 -6
1 #include <iostream> 2 #include <stdio.h> 3 #include <math.h> 4 using namespace std; 5 double EPS = 1e-6; 6 double findValue(double x) { 7 return x*x*x - 5*x*x +10*x -80; 8 } 9 10 int main() { 11 double first = 0, second = 100; 12 double midX = first + (second - first)/2.0; 13 double midVlaue = findValue(midX); 14 while( fabs(midVlaue) > EPS) { 15 if(midVlaue > 0) { 16 second = midX; 17 } else { 18 first = midX; 19 } 20 midX = first + (second - first)/2.0; 21 midVlaue = findValue(midX); 22 23 } 24 printf("%.8lf", midX); 25 return 0; 26 }
标签:code class using div else mat bsp double name
原文地址:https://www.cnblogs.com/zhishoumuguinian/p/9913112.html