级数求和

来源:互联网 发布:我的世界0.15.0暮色js 编辑:程序博客网 时间:2024/09/21 09:21

include

using namespace std;
int main()
{
double k;
int n=0;
double sn=0; //使用double精度
cin>>k;
while (sn<=k) //知道不满足跳出
{
n++;
sn+=1.0/n; //是+= 先加后等于!

}cout<<n;return 0;             //不要漏掉

}

0 0