c语言:用迭代法求平方根中x0=a/2什么意思
#include<stdio.h>#include<math.h>intmain(){floatx0,x1,a;printf("enterapositivenumber:...
#include <stdio.h>
#include <math.h>
int main()
{
float x0,x1,a;
printf("enter a positive number:");
scanf("%f",&a);
x0=a/2;
x1=(x0+a/x0)/2
do
{x1=x2;
x1=(x0+a/x0)/2;
}
while(fabs(x0-x1)>=le-5);
printf("The square root of %5.2f is %8.5f\n",a,x1);
retur0 0;
} 展开
#include <math.h>
int main()
{
float x0,x1,a;
printf("enter a positive number:");
scanf("%f",&a);
x0=a/2;
x1=(x0+a/x0)/2
do
{x1=x2;
x1=(x0+a/x0)/2;
}
while(fabs(x0-x1)>=le-5);
printf("The square root of %5.2f is %8.5f\n",a,x1);
retur0 0;
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询