C语言阶乘 紧急 !!!!!!!!!!!!!!!在线等
来源:百度知道 编辑:UC知道 时间:2024/06/20 02:58:09
求救 !!!!!!!!!
求下面和式前N项的值,要求从键盘输入n和x(如n=5,x=2.0)
1+x/1!+x2/2!+x3/3!+.......+xn/n!
有高手会吗 帮帮忙
x1为x的1次方 其余类似
求下面和式前N项的值,要求从键盘输入n和x(如n=5,x=2.0)
1+x/1!+x2/2!+x3/3!+.......+xn/n!
有高手会吗 帮帮忙
x1为x的1次方 其余类似
#include <stdio.h>
#include <math.h>
int fact( int n )
{
if( n== 1 )
return 1;
return fact(n-1) * n;
}
int main()
{
int n;
double x, sum=1.0;
scanf("%d%lf",&n,&x);
for( int i=1; i<=n; ++i )
sum += pow(x,i) / fact(n);
printf("sum = %f\n",sum);
return 0;
}
x1 x2 x3 ... xn是什么东西?