“21天好习惯”第一期-16

求n分之一序列的前n项和

#include <stdio.h>
int main()
{
    int N;
    int a=1;
    float s=0.0;
    scanf("%d",&N);
    while (a<=N)
    {
        s=s+1.0/a;
        a++;
    }
    printf("sum = %.6f",s);
    return 0;
}

5
sum = 2.283334
Process returned 0 (0x0)   execution time : 1.172 s
Press any key to continue.
 

100
sum = 5.187378
Process returned 0 (0x0)   execution time : 2.607 s
Press any key to continue.
 

上一篇:穷举法求因子


下一篇:JetBrains GoLand 以debug运行Go程序时出现could not launch process: decoding dwarf section info at offset 0x0: