求问,哪里有问题

P1035 [NOIP2002 普及组] 级数求和

younger_111 @ 2023-12-26 15:41:36

代码

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

by Syz2012 @ 2023-12-27 16:44:26

把s=0改成s=1


|