c - 为什么我不能用 C 代码制作这个系列

标签 c series

我尝试在 C: 中编写下面的系列
系列:(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

最佳答案

因为变量yint,所以将pow()的返回值存放在其中截断。阅读the manual page for pow() .

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

关于c - 为什么我不能用 C 代码制作这个系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19836940/

相关文章:

c - 如何对包含 NaN 的 C 数组进行排序

c- recvfrom 错误 22

python - 系列 : dynamic transposition optimization

python - 验证时间序列中的时间戳

scala - 在scala中使用流定义系列

c - 在 Linux 中从 C 显式打开 stdout

c - 如何在linux中实现2个定时器

OpenGL 模型 View 矩阵 4x4 的紧凑表示

c++ - 系列的第n项

java - 计算一个系列