死循环,求大神解释

P1035 [NOIP2002 普及组] 级数求和

cdehguiw @ 2017-09-29 14:37:31

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,n;
    int i;
    n=0;
    i=0;
    cin>>k;
    while(n<=k)
      {
          i++;
          n=n+1.0/i;
      }
    cout<<i<<endl;
    return 0;
}

by YanYH @ 2017-09-29 14:43:31

把int改成long double 就行了


|