h1046782759 @ 2016-08-29 19:25:49
#include<stdio.h>
#include<stdlib.h>
int main()
{
int k;
double s=0,d;
scanf("%d",&k);
for(int n=1;n<999999999;n++)
{
d=1/n;
s=s+d;
if(s>k)
{
printf("%d",n);
break;
}
}
return 0;
}
by 霍霍 @ 2016-09-01 17:46:32
n 不能是int型
by shiniankongcheng @ 2016-09-08 14:32:50
d=1/n;这里得到的d是int型,不是你定义的double,改成d=1.0/n就好了
by Preccc_LHW @ 2016-09-24 15:20:28
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
int i,k,n;
double sn=1.0;
cin>>k;
for(n=2;sn<=k;sn=sn+1.0/n,n++){}
cout<<n-1;
}