1

我试图在 C:
series :中写下面的系列(1^1),(2^(1/2)),(6^(1/4)),(24^(1/8)),...,((n!)^((1/2)^n))

C代码:

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


int fact(int x){
  if (x==1)
    return 1;
    else return x*fact(x-1);
}


int main(){
    int x,y;
    scanf("%d",&x);
    y=x;
    x=fact(x);
    y=pow(0.5,y-1);
    double h;
    h=pow(x,y);
    printf("\n%lf" ,h);
    return 0;
}

为什么总是打印1.00000

4

2 回答 2

6

因为变量yint,所以在其中存储的返回值pow()会被截断。阅读手册页pow()

请检查您如何在编译器中启用所有警告,并查看编译器输出

于 2013-11-07T13:16:44.333 回答
2

函数作为参数pow(a,b)double返回double。尝试替换intdouble.

于 2013-11-07T13:19:52.407 回答