用C语言编写一个程序,计算数列2/1,3/2,5/3,8/5,13/8…前n项之和
发布网友
发布时间:2022-05-26 14:57
我来回答
共4个回答
热心网友
时间:2023-10-23 01:57
#include <stdio.h>
#include <math.h>
int main(void)
{
int n;
double i, j, k;
double res = 0;
printf("please input n:");
scanf("%d", &n);
i = 1;
j = 1;
while(n--)
{
k = i;
i = k + j;
j = k;
res += i / j;
}
printf("The result is %lf\n", res);
return 0;
}
热心网友
时间:2023-10-23 01:58
#include<stdio.h>
int main()
{
int f[100]={0,2,3};
int F[100]={0,1,2};
int i;
for(i=3;i<100;i++)
{
f[i]=f[i-1]-f[i-2];
F[i]=F[i-1]+F[i-2];
}
int n;
while(scanf("%d",&n)!=EOF)
{
double sum=0;
for(i=1;i<=n;i++)
{
sum+=f[i]/1.0/F[i];
}
printf("%.2lf\n",sum);
}
return 0;
}
热心网友
时间:2023-10-23 01:58
#include <stdio.h>
int main()
{
int a=2, b=1, n;
double s = 0;
scanf( "%d", &n );
while ( n-- )
{
s += (double)a/b;
a += b;
b = a-b;
}
printf( "%lf\n", s );
return 0;
}
热心网友
时间:2023-10-23 01:59
#include<stdio.h>
int main()
{
int a;
int b;
int i;
c=0;
a=1;
i=2;
scanf("%d",&n)
for (s=1;s<=n;s++)
{
b=i/a;
i=a+b;
c=b+c;
}
printf("%.2lf\n",c);
}