解法如下:
#include
#include
int main()
{
float fValueA,fValueX,fValueX1;
printf("请输入被开根数:");
scanf("%f",&fValueA);
fValueX1=fValueA;
do{
fValueX1=(fValueX+fValueA/fValueX)/2;
if(fabs(fValueX-fValueX1)<1.0e-7)break;
fValueX=fValueX1;
}while(true);
printf("开平方根结果:%f",fValueX1);
return 0;
}
#include
#include
int main()
{float fValueA,fValueX,fValueX1;
printf("请输入被开根数:");
scanf("%f",&fValueA);
fValueX=fValueA;//这里应给X赋值而不是X1。。//
do{
fValueX1=(fValueX+fValueA/fValueX)/2;
if(fabs(fValueX-fValueX1)<1.0e-7)break;
fValueX=fValueX1;
}while(1);
printf("开平方根结果:%f",fValueX1);
return 0;
}