waterblock79 @ 2018-10-07 11:17:47
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int n=0,k,i;
long double sn=8848;
cin >> k;
while(sn>k)
{
n++;
sn=0;
for(i=1;i<=n;i++)
{
sn=sn+(1/i);
}
}
cout << n << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
by skiy_gyx @ 2018-10-07 11:19:13
这道入门题您确定要思路
纯模拟OK?
#include<bits/stdc++.h>
using namespace std;
int main(){
int k;
cin>>k;
double n=0.0;
for(double i=1;;i++){
n+=1/i;
if(n>k){
cout<<i<<endl;
break;
}
}
return 0;
}
by miaojiexi @ 2018-10-07 11:19:18
@waterblock79 long double 可能有点危险
by miaojiexi @ 2018-10-07 11:19:51
sn=sn+(1/i);
改sn=sn+(1.0/i);试试
by 森岛_帆高 @ 2018-10-07 11:20:43
8848。。。。
by Mr_Wu @ 2018-10-07 11:35:34
return EXIT_SUCCESS是啥。。
by DeviceContext @ 2018-10-07 11:37:47
system("pause");
可怕。。。
by Eason_AC @ 2018-10-07 11:41:50
#include <bits/stdc++.h>
using namespace std;
int main() {
double Sn=1;
int k,i;
cin>>k;
for(i=2; ; i++) {
Sn+=(double)1/i;
if(Sn>k)
break;
}
cout<<i;
return 0;
}
这个题目水题呀,注意一下,不加double会发生很奇怪的事,参考一下,但别抄