c 语言的一个疑惑

来源:百度知道 编辑:UC知道 时间:2024/06/24 06:01:11
# include <stdio.h>
# include <windows.h>
# include <math.h>
int squre (int y);

int main (void)
{
int x;
for (x=1;x<=10;x++) {
printf ("%d ",squre(x));
}
printf ("\n");
system ("pause");
return 0;
}

int squre (int y)
{
return pow(y,2);
}

为什么出来的是1 4 9 16 25 36 49 64 81 99
不应该是1 4 9 16 25 36 49 64 81 100吗?
大虾们帮帮忙~~~
我用的编译器是Dev-C++ 4.9.9.2
另外我试了pow(y,3) pow(y,4) pow(y,5) 貌似就双数在最后有少1的问题~~

如果是浮点的问题,为什么奇数就是正确的啊,可见不是浮点的问题嘛

楼主的编译器问题吧。我用VC6.0编译正确,无问题。

请看图片。

两外,pow的参数为double,就算不是问题源,也是不应该这样定义。

可能编译器的解释不同吧。

# include <stdio.h>

# include <math.h>
int squre (int y);

void main()
{
int x;
for (x=1;x<=10;x++) {
printf ("%d ",squre(x));
}
printf ("\n");

}

int squre (int y)
{
return pow(y,2);
}

如果改成这