great_mad @ 2023-11-11 10:46:27
#include <stdio.h>
int main()
{
int k;
scanf("%d",&k);
double sum;
int n;
do{
for(n=1; ;n++){
sum+=(1.0/n);
}
}while(sum>k*1.0);
printf("%d",n);
return 0;
}
by DustyMark @ 2023-11-11 10:58:47
@great_mad 用普通的while足矣,里面不要for,但判断是sum<=k吧,
by Kelly_1 @ 2023-12-18 10:34:20
用一个for循环加一个if判断也行