long jc(int n){//不使用递归
int i = 1
long m = 1
for(i = 1i <= 50i ++)
m *= i
return m
}
long jc(int n){ //使用递归
if(n)
return (long)(n * jc(n-1))
else
return 1
}
int main(){使用for循环
float e = 1.0
int i = 1
for(i = 1i <= 50i ++){
e += 1/jc(i)
}
printf("%f",e)
return 0
}
int main(){//使用while
float e = 1.0
int i = 1
while(i <= 50){
e += 1/jc(i)
i ++
}
printf("%f",e)
return 0
}
/*
2.718282
Press any key to continue
*/
#include <stdio.h>unsigned Fact(unsigned n) {
unsigned i,fact = 1
for(i = 1 i <= n ++i)
fact *= i
return fact
}
double Exp(int n) {
double e = 1.0
int i
for(i = 1i <= ni++)
e += 1.0/Fact(i)
return e
}
int main() {
printf("%lf\n",Exp(20))
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)