码迷,mamicode.com
首页 > 其他好文 > 详细

求解数列1+1/(1+2)+1/(1+2+3)+......

时间:2020-07-27 23:48:05      阅读:74      评论:0      收藏:0      [点我收藏+]

标签:clu   style   class   lan   href   文章   tps   https   target   

/*
求解数列1+1/(1+2)+1/(1+2+3)+......
*/
#include <stdio.h>
double fun(int n){
    double s=0;
    int i,a=0;
    for(i=1;i<=n;i++){
        a=a+i;
        s=s+1.0/a;
    }
    return s;
}
int main(){
    int n;
    double t;
    printf("请输入一个正整数n:");
    scanf("%d",&n);
    t=fun(n);
    printf("当n=%d时,数列的值是%f\n",n,t);
    return 0;
}

收录于文章《885程序设计考点狂背总目录中

求解数列1+1/(1+2)+1/(1+2+3)+......

标签:clu   style   class   lan   href   文章   tps   https   target   

原文地址:https://www.cnblogs.com/byczyz/p/13387039.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!