求大佬教一下小萌新这个是哪里错了?

P1035 [NOIP2002 普及组] 级数求和

Luoqiu19 @ 2019-11-04 19:02:41

include<stdio.h>

include<math.h>

int main() { int n,k; double m; double sum=0;

scanf("%d",&k);

for(n=1;sum<=k;n++)
{
    m=1/n;

    sum+=m;
}

printf("%d",n-1);

}


by jxyzs @ 2019-11-04 19:04:10

@Luoqiu19 1/n,整数和整数,结果会是整数


by Luoqiu19 @ 2019-11-04 19:04:53

@jxyzs 好的谢谢大佬:)


by jxyzs @ 2019-11-04 19:05:07

还有 希望更丰富的展现?使用Markdown


|