re求助

P1035 [NOIP2002 普及组] 级数求和

Pangaoyuan01 @ 2024-06-07 16:44:43

#include<bits/stdc++.h>
using namespace std;
double n;
int k,i;
int main(){
    cin>>k;
    for (i=1;n<=k;i++) n+=1/i;
    cout<<i;
}

by GWOI @ 2024-06-07 16:46:25

@Pangaoyuan01 记得用double啊!!

1/i 中,1i 都是 int 类型的,所以答案也是 int 类型的!


by Pangaoyuan01 @ 2024-06-07 16:54:24

谢谢


|