Plum_Steven @ 2022-02-04 12:40:20
#include <iostream>
using namespace std;
int main()
{
int n=1, k;
float total;
cin >> k;
while(1)
{
total += 1 / n;
n++;
if (total > k)
{
break;
}
}
cout << total;
return 0;
}
by Onana_in_XMFLS @ 2022-02-04 13:48:19
草这楼都是人才
by cbdsopa @ 2022-02-04 13:55:25
@Plum_Steven 你要输出n,不是total
by zhy137036 @ 2022-02-04 14:10:55
或者直接摆烂不写
by Syamoe @ 2022-02-04 14:32:14
楼上正解
by Syamoe @ 2022-02-04 14:33:31
@Plum_Steven 注意 float 的精度