求助0分c++

P1035 [NOIP2002 普及组] 级数求和

songchunxi @ 2023-03-12 14:41:18


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

by NTFS @ 2023-03-12 15:04:11

分数最终输出不是小数吗 开double吧


by __QHY__ @ 2023-03-12 15:08:21

开double !


by songchunxi @ 2023-03-12 15:11:01

好的,谢谢各位大佬


by Him_jntm @ 2023-07-22 15:55:29

感谢XDM


|