胡漠杨 @ 2020-03-14 21:06:04
#include<stdio.h>
float sum(float (1/n));
int main()
{
int n,k;
scanf ("%d",&k);
for (n=1;;n++)
{
if (k<sum(1/n))
{
break;
}
printf ("%d",n);
}
return 0;
}
float sum(float (1/n))
{
int n;
if (n==1)
{
return 1;
}
else
{
return sum(1/(n-1))+(1/n);
}
}
by UnyieldingTrilobite @ 2020-03-14 21:06:36
这个函数······看不懂
by 胡漠杨 @ 2020-03-14 21:08:40
@return20071007 我想实现当n=1时返回1,当n≠1时返回1/(n-1) + 1/n。
by CSP_Sept @ 2020-03-14 21:08:52
float sum(float (1/n));
是什么意思
by Marser @ 2020-03-14 21:09:09
能不能好好学一下函数啊
by Marser @ 2020-03-14 21:09:21
形参哪有这么定义的啊
by Marser @ 2020-03-14 21:09:55
还有float
有什么用啊,不用double
精度怎么够啊
by UnyieldingTrilobite @ 2020-03-14 21:10:25
用循环好了······
伪代码:
I have some integers k,n;
I have one decimal s;
Read in k;
While the value of s is less than the value of k or the value of s equals the value of k do{
Please let the value of n be the value of n plus 1;
Then Let the value of s be the value of s plus 1.0 divided by n;
}
Print out n;
Print out '\n';
by CSP_Sept @ 2020-03-14 21:10:43
double sum(double n)
才对
by UnyieldingTrilobite @ 2020-03-14 21:10:52
怎么感觉今天Marser神仙到处D人
by Marser @ 2020-03-14 21:11:03
@return20071007 真实自然语言编程