函数,编写函数计算N!,调用该函数计算下式的值
S=1+1/(1+4!)+1/(1+4!+7!)+...+1/(1+4!+7!+...+19!)题目如上,求大佬们教教怎么写
程序代码://s = 1/(1!)
// + 1/(1!+4!)
// + 1/(1!+4!+7!)
// + ……
// + 1/(1!+4!+7!+...+19!)
#include <stdio.h>
int main( void )
{
unsigned long long f1 = 1;
unsigned long long f2 = 0;
double f3 = 0;
for( unsigned i=1; i<=19; ++i )
{
f1 *= i;
if( (i+2)%3 == 0 )
{
f2 += f1;
f3 += 1.0/f2;
}
}
printf( "%f\n", f3 );
}
程序代码:#include<stdio.h>
long long jiecheng(int m)
{
long long x=1;
int i;
for(i=1;i<=m;i++)
x=x*i;
return x;
}
float jc(int k)
{
float i,x,y,S=1.0;
int m;
long long a,s=1;
for(m=4;m<=k;m=m+3)
{
a=jiecheng(m);
s+=a;
y=1.0/s;
S+=y;
}
return S;
}
int main()
{
float s;
s=jc(1+3*1);
printf("%f",s);
return 0;
}