零分求助

P1035 [NOIP2002 普及组] 级数求和

IAKIOI14141 @ 2023-05-23 17:48:42


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

by rnf5114 @ 2023-05-23 17:53:15

@duruixuan i要从1开始


by Killua_Zaoldyeck @ 2023-05-23 17:54:10

@duruixuan S_n= 1+\frac{1}{2}+\frac{1}{3}+…+\frac{1}{n} emmm,,,你仔细看看这个


by IAKIOI14141 @ 2023-05-23 18:08:01

我又想了想,过了,谢谢。


by hanjinshou @ 2023-08-20 11:40:42

@Killua_Zaoldyeck 代码里怎么实现分数相加啊


|