#include <stdio.h>
#include <stdlib.h>
#include <math.h> //数学头文件,里面含有pow函数
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//计算n为1~100的[(-1)^(n+1)*(1/n)]!
int main(int argc, char *argv[]) {
double jiechenghe=0,n=1; //定义double型阶乘和
for(n;n<=100;n++) //分别计算n从1~100的数
{
jiechenghe+=pow(-1,n+1)*(1.0/n); //阶乘和等于n从1~100的数之和,调用pow()函数,实现计算
}
printf("n为1~100的[(-1)^(n+1)*(1/n)]!为%.4lf",jiechenghe); //输出阶乘和,double型精确到小数后6为,因为100+的缘故,精确度最高是4
return 0;
}
c语言 分数阶乘计算
最新推荐文章于 2023-01-10 10:08:24 发布