nyzhb000919 @ 2017-04-04 17:25:18
#include<iostream>
#include<cstdio>
using namespace std;
int sn(int);
int main()
{
int n,k;
cin>>k;
cout<<sn(1)<<endl;
return 0;
}
int sn(int k)
{
int n=1;
int sum=0;
while(sum<=k)
{
sum=n+1/n;
n=n+1;
}
return n;
}
by 劫控 @ 2017-04-23 19:47:09
1.sum应该是浮点数类型,而且初值等于1.0;
2.应该是sum=sum+1/n;
3.函数的实参应该是k不是1;
4.n的递增应该在sum=sum+1/n前面;
by gcrx @ 2017-04-25 18:06:09
要做累加哦!