这个程序杂个编写

来源:百度知道 编辑:UC知道 时间:2024/05/23 04:55:11
【程序设计】
--------------------------------------------------

功能:求一分数序列2/1,3/2,5/3,8/5,13/8,21/13…
的前n项之和。
说明:每一分数的分母是前两项的分母之和,每一分数的
分子是前两项的分子之和
例如:求前20项之和的值为32.660259。

------------------------------------------------*/

#include "stdio.h"

float fun(int n)
{

/**********Program**********/

/********** End **********/

}

main()
{
float y;
y=fun(20);
printf("y=%f\n",y);
yzj();

}

yzj()
{
FILE *IN,*OUT;
int iIN,i;
float fOUT;
IN=fopen("in.dat","r");
if(IN==NULL)
{
printf("Please Verify The Currernt Dir..It May Be Changed");
}
OUT=fopen("out.dat","w");
if(OUT==NULL)
{
printf("Please Verify The Current Dir.. It May Be Changed"

float run(int n)
{
float* z=new float[n];
float* m=new float[n];
float lj=0.0;
for(int i=0;i<n;i++)
{
float thisZ;
float thisM;
if(i==0)
{
thisZ=2.0;
thisM=1.0;
}
else if(i==1)
{
thisZ=3.0;
thisM=2.0;
}
else
{
thisZ=z[i-2]+z[i-1];
thisM=m[i-2]+m[i-1];
}
z[i]=thisZ;
m[i]=thisM;
lj+=thisZ/thisM;
}
delete []z;
delete []m;
return lj;
}

这个还要100分?