#include <math.h>
#include <stdio.h>
main()
{float x,t,c;
int a;
scanf("%d",&a);
x=1;
do
{
t=x;x=(1.0/2)*(x+a/x);c=x-t;
}while(fabs(c)/x>1e-5);
printf("%f",x);
getch();
}
这个可以 而为啥把while语句改一下就是不行呢?
#include <math.h>
#include <stdio.h>
main()
{float x,t,c;
int a;
scanf("%d",&a);
x=1;
while(fabs(c)/x>1e-5)
{
t=x;x=(1.0/2)*(x+a/x);c=x-t;
}
printf("%f",x);
getch();
}
为啥就是不行