Object_ @ 2018-07-24 18:33:57
#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
int main(){
int k;
cin>> k;
double number=0;
int tempNumber=1;
for(;number<k;){
number=number+(double)1.0/tempNumber;
tempNumber++;
}
cout<<tempNumber;
return 0;
}
by 小粉兔 @ 2018-07-24 18:58:26
输入2 输出4
by Object_ @ 2018-07-24 18:59:22
哦哦,明白了,是因为tempNumber写到了后面,应该写到循环体的开头
by Object_ @ 2018-07-24 18:59:43
@Object_ 这样的话tempNumber也应该初始化为0了