相关疑难解决方法(0)

使用我的编译器和操作系统时,为什么当n = 5时pow(n,2)返回24?

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int n,i,ele;
    n=5;
    ele=pow(n,2);
    printf("%d",ele);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出是24.

我在Code :: Blocks中使用GNU/GCC.

怎么了?

我知道pow函数返回一个double,但是25适合一个int类型所以为什么这个代码打印24而不是25?如果n=4; n=6; n=3; n=2;代码有效,但有五个代码没有.

c math.h c-standard-library

23
推荐指数
1
解决办法
4809
查看次数

标签 统计

c ×1

c-standard-library ×1

math.h ×1