求助,???

P1035 [NOIP2002 普及组] 级数求和

qiuqiu701008 @ 2016-09-21 15:25:09

#include <iostream>
using namespace std;
int main()
{
    int k;
    int n=1;
    cin >> k ;
    double j = 0;
    do
    {
        j = 1.0/n + j;
        n++;
    } while (j<k);
    cout << n;
}

by 46days @ 2016-09-26 18:25:39

#include <iostream>
using namespace std;
int main()
{
    int k;
    int n=0;
    cin >> k ;
    double j = 0;
    do
    {
        n++;
        j = 1.0/n + j;
    } while (j<=k);
    cout << n;
}

by LiBai041208 @ 2016-10-07 17:36:51

#include<stdio.h>
int main()
{
    double s=0;
    int k,n=1;
    scanf("%d",&k);
    while(s<=k)
    {
        s+=1.0/(n++);
    }
    printf("%d\n",n-1);
    return 0;
}

by Critical丨临界 @ 2016-10-09 20:19:14

#include <iostream>
using namespace std;
int main()
{
    int k,n;
    double sum=0;
    cin >> k;
    for(n = 1;sum <= k;n = n+1)
    {
        sum = sum + 1.0/n;
    }
    cout << n-1;
    return 0;
}

by 电脑渣渣 @ 2016-10-12 17:08:29

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

|