标签:des style blog color strong 2014
#include<stdio.h> double a, b, c, d; double Func(double x) { double result; result = a * x * x * x + b * x * x + c * x + d; // 计算f(x)的值 return result; } int main() { double x; scanf("%lf%lf%lf%lf", &a, &b, &c, &d); for(int i = -100; i <= 100; i++) { if(Func(i * 1.0) * Func((i + 1) * 1.0) < 0) // 判断该区间中是否有根 { double low = i * 1.0, high = (i + 1) * 1.0, mid; while(high - low > 1e-8) { mid = (high + low) / 2; if(Func(mid) * Func(high) <= 0) // 进行折半查找 low = mid; else high = mid; } printf("%.2lf ", mid); } if(Func(i * 1.0) == 0) // 还有一种情况就是根就在区间边界上 printf("%.2lf ",i * 1.0); } return 0; }
标签:des style blog color strong 2014
原文地址:http://blog.csdn.net/userluoxuan/article/details/37725909