#include<stdio.h>
#include<math.h>
int main()
{
float num,num2=2,temp=1;
scanf("%f", &num);
while(fabs(temp-num2)> 0.00001)
{
temp = num2;
num2 = (temp + num/temp)/2;
}
printf("%.3f", temp);
return 0;
}//task 1
#include<stdio.h>
#include<math.h>
int main()
{
double n,a,b;
scanf("%lf", &n);
a = n / 2;
b = (a + n / a) * 1.0 / 2.0;
while (fabs(b-a) > 0.00001)
{
a = b;
b = (a + n / a) * 1.0 / 2.0;
}
printf("%.3lf", b);
return 0;
}//task 2
YTU : C语言迭代法求平方根
于 2022-10-25 21:11:02 首次发布