标签:amp math.h \n style 2.0 std scanf pre code
1 #include<stdio.h> 2 #include<math.h> 3 float f(float x){ 4 return (x*x*x-x-1); 5 } 6 int main(){ 7 float x1, x2; 8 scanf("%f,%f", &x1, &x2); 9 10 float cen=(x1+x2)/2.0; 11 float vc=f(cen); 12 while(fabs(vc) > 1e-6){ 13 14 if(vc > 0){ 15 x2=cen; 16 }else if(vc < 0){ 17 x1=cen; 18 }else{ 19 break; 20 } 21 22 cen=(x1+x2)/2.0; 23 vc=f(cen); 24 } 25 printf("x=%6.2f\n", cen); 26 }
标签:amp math.h \n style 2.0 std scanf pre code
原文地址:https://www.cnblogs.com/zhishoumuguinian/p/10642204.html