18. 求交错序列前N项和

求交错序列前N项和

#include <stdio.h>

int main()
{
    int numerator, denominator, flag, i, n;
    double item, sum;
    while (scanf("%d", &n) != EOF)
    {
        flag = 1;
        numerator = 1;
        denominator = 1;
        sum = 0;
        for (i = 1; i <= n; i++)
        {
            item = flag*1.0*numerator/denominator;
            sum = sum+item;
            flag = -flag;
            numerator = numerator+1;
            denominator = denominator+2;
        }
        printf("%.3f\n", sum);
    }
    return 0;
}
上一篇:天津*应急系统之GIS一张图(arcgis api for flex)讲解(七)地图打印模块


下一篇:GoLang学习之数据类型