题解 | #牛牛学数列3#

牛牛学数列3

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

#include <stdio.h>

int main() {
    int n = 0;

    while (~scanf("%d", &n))    
    {
        double sum = 0;
        double odd = 0;
        int sign = 1;
        for (double i = 1; i <= (2 * n - 1); i += 2)
        {
            odd += (sign * i);
            sign = (-sign);
            sum += (1 / odd);
        }
        printf("%.3lf\n", sum);
    }

    return 0;
}

全部评论

相关推荐

M_bao:换个排版吧哥们,看着费劲
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务