哪错了

P1035 [NOIP2002 普及组] 级数求和

myx1221 @ 2017-02-26 13:34:17

#include <iostream>
#include <cstdio>
#include <cmath> 
using namespace std;
int main()
{
    int K,N;
    long double sum;
    cin>>k;
    sum=0;i=0;
    while (sum<=k)
    {
        N+=1;
        sum=sum+(1/N);
    }
    cout<<N<<endl; 
    return 0;
}

by ZYBGMZL @ 2017-02-26 14:44:13

sum=sum+(1/N);

这句里面N是整形,(1/N)也是整形,除了1/1是1以外,(1/N)都是0


by ZYBGMZL @ 2017-02-26 14:44:49

@爷爷


by 徐熙凯 @ 2017-02-26 15:08:42

#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
    int a,i=0;
    double s=0;
    cin>>a;
    while (s<=a)
    {
        i=i+1;
        s=s+1.0/i;
    }
    cout<<i;
    return 0;
}
我是这样的

by myx1221 @ 2017-03-04 07:17:12

谢了


|