陈生 @ 2017-09-26 10:56:04
#include<cstdio>
#include<iostream>
using namespace std;
int n,K;
double Sn=0.0;
int main()
{
scanf("%d",&K);
while(Sn<K)
{
Sn+=1.0/n;
n++;
}
cout<<n;
return 0;
}
by Ryuuko @ 2017-09-26 11:23:18
n的初值0, 1 / 0的double类型=inf
by 陈生 @ 2017-09-26 14:48:41
@张明华 inf是?
by 陈生 @ 2017-09-26 14:55:52
@张明华 我把n的初值赋成1 输出“n-1” (消除循环多出来的1)AC了 但是inf是什么?
by wxgwxg @ 2017-09-26 17:09:07
@陈生 inf就是正无穷
#include <iostream>
using namespace std;
double a = 0;
int main()
{
cout << 1 / a;
return 0;
}
可以运行试试
by Ryuuko @ 2017-09-26 17:19:28
@wxgwxg 楼上说的对
by 陈生 @ 2017-09-27 15:23:24
@张明华 inf 我是弱鸡 不懂0.0
by wxgwxg @ 2017-10-23 12:26:30
@张明华