Problem H: 计算数列和2/1,3/2,5/3,8/5......

#include<stdio.h>
int main(){
    int i,n;
    scanf("%d",&n);
    float sum=0.0;
    float a=1;
    float b=2;
    for(i=1;i<=n;i++){
        sum=sum+1.0*b/a;
        int c=a;
        a=b;
        b=c+b;
    }
    printf("s=%.2f\n", sum);
    return 0;
}

 

posted @ 2018-10-21 13:38  MichaelCecil  阅读(1528)  评论(0编辑  收藏  举报