phasetest @ 2022-01-21 21:15:23
#include <stdio.h>
int main () {
int k,n;
double a=0.0;
scanf("%d",&k);
for (n=1;a<k*1.0;n++){
a=a+(1.0/n);
}
printf("%d",n);
return 0;
}
by Justin090102 @ 2022-01-21 21:17:27
@phasetest printf("%d",n-1);
by phasetest @ 2022-01-21 21:18:46
@Justin090102
by Justin090102 @ 2022-01-21 21:20:28
@phasetest 第n次循环结束后a>k了,而这个时候应输出n,但n又自增了一次,然后判断为假退出
by phasetest @ 2022-01-21 21:31:45
@Justin090102 谢谢大佬!