BabyChen @ 2021-05-08 18:31:07
#include<stdio.h>
#include<stdlib.h>
int main()
{
double sn=0;
int k,n;
scanf("%d",&k);
for (n=1;sn<=k;n++)
{
sn=sn+ 1/n;
}
printf("%d",n);
return 0;
}
求助求助,哪错了
by reailikezhu @ 2021-05-08 18:35:48
把 cdouble
试试。
by 朦胧细雨 @ 2021-05-08 19:00:19
你要把“1/n”进行强行转换
sn=sn+(double)1/n;
然后你输出的n还要减一也就是
printf("%d",n-1);
by 力巴尔 @ 2021-05-30 13:43:23
把1 / n改成1.0 / n