這是我寫的代碼,找到約平方根非完美數字(按照0.0001的順序,也是完美平方的精確平方根,它與非完美。平方數,但並不完美。當我把25它給5.000068查找數字的近似平方根
#include<stdio.h>
int main()
{
float a,i,count;
scanf("%f",&a);
for(count=1;(1);count=count+0.0001)
{
i=count*count;
if (i<=a)
break;
}
printf("%f",count);
return 0;
}
幾乎好像你正在運行到一個浮點精度問題。 – hd1 2014-09-06 04:57:43
@ hd1但是我把i> = a。所以當count = 5時爲什麼不打印5 – 2014-09-06 05:01:01
[C-浮點精度]可能重複(http://stackoverflow.com/questions/9577179/c-浮點精度) – 2014-09-06 05:01:46