题意:输入一个数, 算出1/2 + 1/3 + 1/4 + … + 1/(n+ 1)大于这个数时的最小n。
翻译对我来说是一种折磨! 弱菜不解释...
#include <iostream>
using namespace std;
const int SIZE=300;//当输入达到上限5.20时,SIZE最大为276
double length[SIZE]={0.0};
int main()
{
double len;
int i;
while(cin>>len,len){
for(i=1; ;i++)
{
if(! length[i])
length[i] = length[i-1] +1.0/(i+1.0);
if(length[i]>=len) break;
}
cout<<i<<" card(s)"<<endl;
}
double s;
}