Moxder @ 2016-06-02 19:47:31
#include<stdio.h>
int main()
{
int k,i;
int sn=0;
scanf("%d",&k);
for(i=1;;i++)
{
sn=sn+(1/i);
if(sn>k){
printf("%d",i);
return 0;
}
}
return 0;
}
by doby @ 2016-06-02 21:40:18
那个sn是int形式,直接取整了,所以是个死循环……
by Deny_小田 @ 2016-06-03 16:44:01
楼主应使用double类型 @Moxder
by wh_ZH @ 2016-06-04 07:32:00
楼主可以试试用float或double,但读入要注意,改成%f或%lf
by mraymes @ 2016-08-21 11:37:51
#include<stdio.h>
int k,n=1;
double s=0;
int main()
{
scanf("%d",&k);
while(s<k)
{
s=s+1/n;
n=n+1;
}
printf("%d",n);
return 0;
}
我也是tle。。。
by 林盛昊 @ 2016-08-21 20:22:05
#include<stdio.h>
int k,n=1;
double s=0;
int main()
{
scanf("%d",&k);
while(s<k)
{
s=s+1*1.0/n;
n=n+1;
}
printf("%d",n);
return 0;
}
1是整形变量,除以实数不行
by Moxder @ 2016-10-01 21:59:12
太厉害了,一句话解决了我所有问题:)@林盛昊