A37075. 编写函数fun,函数的功能是:根据以下公式计算s,计算结果作为函数值返回;n通过形参传入。1 1 1S=1 + ── + ─── + … + ──────1+2 1+2+3 1+2+3+…+n例如:若n的值为11时,函数的值为:1.833333注意:部分源程序在文件PROG1.C中。请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。给定源程序:#incl…
填空题
困难
知识点
题目描述
编写函数fun,函数的功能是:根据以下公式计算s,计算结果作为函数值返回;n通过形参传入。
1 1 1
S=1 + ── + ─── + … + ──────
1+2 1+2+3 1+2+3+…+n
例如:若n的值为11时,函数的值为:1.833333
注意:部分源程序在文件PROG1.C中。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include<stdio.h>
float fun(int n)
{
____1____
____2____
for(____3____)
{
____4____
for(____5____)
t+=j;
____6____
}
return s;
}
main()
{
int n;
float s;
printf("\nPlease enter N:");
scanf("%d", &n);
s = fun(n);
printf("the result is: %f\n", s);
NONO();
}
参考答案
<p>1. 正确答案: int i, j, t;</p><p>2. 正确答案: float s=0;</p><p>3. 正确答案: i=1;i<=n;i++</p><p>4. 正确答案: t=0;</p><p>5. 正确答案: j=1;j<=i;j++</p><p>6. 正确答案: s=s+1./t;</p>
上一题
下一题