我尝试在 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
?
最佳答案
因为变量y
是int
,所以将pow()
的返回值存放在其中截断。阅读the manual page for pow()
.
请检查您如何在编译器中启用所有警告,并查看编译器输出。
关于c - 为什么我不能用 C 代码制作这个系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19836940/