Hinsky @ 2020-02-20 21:32:03
#include<stdio.h>
int main()
{
double S=0;
int i,k,n=0;
scanf("%d",&k);
for(i=1;i<n+5;i++)
{
S += (double)1/i;
n++;
if(S>k)
n++;
break;
}
printf("%d",n);
return 0;
}
如果把break;前面的n++;去掉就是正确答案,但是加上这个输入1后输出也是1,不应该输出3吗?求大佬指点一下
by 芜湖起飞 @ 2020-02-20 21:37:54
因为break不在if之内啊
by 芜湖起飞 @ 2020-02-20 21:38:57
@Hinsky
by VTloBong @ 2020-02-20 21:57:07
没加大括号
by tiger0133 @ 2020-02-20 22:07:38
#include<stdio.h>
int main()
{
double S=0;
int i,k,n=0;
scanf("%d",&k);
for(i=1;i<n+5;i++)
{
S += (double)1/i;
n++;
if(S>k)
{
n++;
break;
}
}
printf("%d",n);
return 0;
}