楼主,首先我想说一下你题目可能不小心打错了,我猜应该是求
(x/1!)+(x*x*x/3!)+(5个x相乘/5!)+……+((2n-1)个X相乘/(2*n-1)!)
当N为某值时上式为多少吧!
我帮你编写的代码如下(很用心编写的哦):
#include "stdio.h"
#include "math.h"
int power(int n)
{
if(n!=0) return n*power(n-1);
else return 1;
}
float computer(float x,int n)
{
return pow(x,2*n-1)/power(2*n-1);
}
void main()
{
int n,i;
float x,sum;
printf("please input the value of x and n\n");
scanf("%f %d",&x,&n);
printf("x=%f,n=%d\n",x,n);
for(i=1;i<=n;i++) sum+=computer(x,i);
printf("(x/1!)+(x*x*x/3!)+(x*x*x*x*x/5!)+……+(x*x*x*……/(2*n-1)!)=%f\n",sum);
}
程序我在Turbo C 2.0 Turbo C++ 3.0 和 Microsoft Visual C++ 6.0运行都通过了. 保证没问题!
请参考一下吧,呵呵.
#include "stdio.h"
float fun1(float x,int n){
float s;
if(n==1) s=x;
else s=x*fun1(x,n-1);
return s;}
float fun2(int n){
float s;
if(n==1) s=1;
else s=fun2(n-1)*n;
return s;
}
float fun3(float x,int n){
float y;
if(n==1) y=x;
else y=fun3(x,n-1)+fun1(x,n)/fun2(n);
return y;}
void main(){
float x,y;
int n;
scanf("%f,%d",&x,&n);
y=fun3(x,n);
printf("%f",y);
}
不明白了
这程序有上面的那么复杂吗?
#include
#include
void count(int n,float x,float y)
{
int f,k,p;
k=2*n-1;
p=1;
float m;
for(;k>0;k--) p=p*k;
m=float (pow(x,(2*n-1)));
if(n%2) f=1;
else f=-1;
y+=m/(f*p);
n--;
if(n!=0) count(n,x,y);
else printf("y=%.3f",y);
}
void main()
{
int n;
float x,y;
y=0;
printf("输入n:");
scanf("%d",&n);
printf("输入x:");
scanf("%f",&x);
count(n,x,y);
}
“y=x/1!-x*x*x/3!+x*x*x*x*x/5-(七个x相剩)/7!+(八个x相剰)/8!..... ”
是不是“y=x/1!-x*x*x/3!+x*x*x*x*x/5-(七个x相剩)/7!+(九个x相剰)/9!..... ”
即y=(x/1!)-(x*x*x/3!)+(5个x相乘/5!)-(7个x相乘)/7!……+(-(-1)^n)*(2n-1个X相乘)/(2*n-1)!)
下面是这个题在TC2中的源程序:
#include
double fac(int m)
{
int i;
double t=1.0;
for(i=1;i<=m;i++)
t*=i;
return t;
}
double t(int m,double x)
{
int j;
double s=1.0;
for(j=1;j<=m;j++)
s*=x;
return s;
}
int g()
{
int k,p=1;
static int r=0;
r++;
for(k=1;k<=r;k++)
p*=(-1);
return -p;
}
main()
{
int m,n,h;
double x,y=0;
printf("Input n,x:");
scanf("%d,%lf",&n,&x);
for(h=1;h<=n;h++)
{
m=2*h-1;
y+=g(n)*t(m,x)/fac(m);
}
printf("\ny=%f\n",y);
}