求分数序列和

题目:有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13…求出这个数列的前20项之和。
程序分析:请抓住分子与分母的变化规律。

递归解决:

12345678910111213141516171819202122
#include <stdio.h>float Cal(float a,float b,int count){    if (count<=0)    {        return 0;    }else    {        float temp = b/a;        float c = a + b;        return (temp + Cal(b, c, count-1));    }}int main({    float a = 1;    float b = 2;    int count = 20;    float ret = Cal(a,b,count);    printf("%lf",ret);    return 0;}
🔍 ×