hunandaxue @ 2023-07-13 15:47:14
#include<iostream>
#include<cstdio>
using namespace std;
int main() {
double s=0;
int n=1;
int k;
cin>>k;
while(s<=k)
{
s=s+1/n;
n++;
}
cout<<n;
return 0; }
by 0x282e202e2029 @ 2023-07-13 15:51:14
by Kong__Bai @ 2023-07-15 00:31:47
s是double类型,n是整形(int)的,1/n是int类型的,所以你的s数据是错误的,应该是s+=1.0/n.