Irascible_boy1_0 @ 2017-08-20 14:58:01
#include<iostream>
using namespace std;
int main() {
int k,a=0;
double c,n=0;
cin>>k;
do {
c=0;
for(n=0; n<=a; n++)
c=c+1/n;
a++;
} while(c<=k);
cout<<n;
}
这样出不来啊
by 攀岩高手 @ 2017-08-22 10:46:58
变量c应该在循环外初始化;for循环和变量a没有意义,应去掉.
#include <iostream>
using namespace std;
int main() {
int k;
double c=0, n=0;
cin >> k;
do {
n++;
c+=1/n;
} while (c<=k);
cout << n;
return 0;
}