#include "math.h"main(){float x1=1.0,x2,a;printf("please input a ");scanf("%f",&a);
do{x2=0.5*(x1+(a/x1));x1=x2;}while(fabs(x2-x1)>=1e-5);printf("aqrt(a)= %10.4f",x2);}输出结果不正确
#include "math.h"main(){float x1,x2,a;printf("please input a ");scanf("%f",&a);x1=1.0;do{x1=x2;x2=0.5*(x1+(a/x1));
}while(fabs(x2-x1)>=1e-5);printf("aqrt(a)= %10.4f",x2);}把迭代的顺序弄错了,使得x1=x2, fabs(x1-x2)=0了,只执行一次就结束了真是晕了!!