题解 | #牛牛学数列3#

牛牛学数列3

https://www.nowcoder.com/practice/f65c726d081c4160a9356eabf0dc21d9

#include <stdio.h>

int main() {
    int n = 0;
    scanf("%d", &n);

    int i = 0, flag = 1, tem = 1;
    float sum = 0.0f, result = 0.0f;
    for (i = 1; i <= n; i++) {
        sum += flag * tem;
        result += 1.0 / (sum);
        flag = -flag;
        tem += 2;
    }

    printf("%.3f", result);

    return 0;
}

全部评论

相关推荐

尊嘟假嘟点击就送:加v细说,问题很大
点赞 评论 收藏
分享
评论
1
收藏
分享
牛客网
牛客企业服务