c求分数序列和
2021-08-8 12:30 1410次
有一个分数序列 q1/p1,q2/p2,q3/p3,q4/p4,q5/p5,.... ,其中 qi+1= qi+ pi, pi+1=qi,p1= 1, q1= 2。比如这个序列前 6 项分别是 2/1,3/2,5/3,8/5,13/8,21/13。求这个分数序列的前 n 项之和。
输入:
输入有一行,包含一个正整数 n(n <= 30)。
输出:
输出有一行,包含一个浮点数,表示分数序列前 n 项的和,精确到小数点后 4 位。
样例输入:
2
样例输出:
3.5000
#include<stdio.h>
int main(){
int a,b,c,d;
double q=1.0,l=2.0,m,n=0;
scanf("%d",&b);
for(a=1;a<=b;a++){
n=l/q+n;
m=l;
l=q+l;
q=m;
}
printf("%.4lf",n);
}
游客91.210.248.* :2022-09-16 17:54
snap chat gay boy cums <br />
[url="https://chatcongays.com"]gay chat lines in atlanta[/url] <br />
free live gay chat rooms
游客91.210.248.* :2022-09-15 10:16
gay webcam chat sites <br />
single gay men chat line highpoint nc <br />
<a href="https://free-gay-sex-chat.com/">chat random gay </a>