问题详情

答题翼 > 问答 > 计算机类考试 > 正文
目录: 标题| 题干| 答案| 搜索| 相关

编写函数fun() 函数的功能是:根据以下公式计算s 计算结果作为函数值返回;n通过形参传入。 S=1+1/(


编写函数fun(),函数的功能是:根据以下公式计算s,计算结果作为函数值返回;n通过形参传入。

S=1+1/(1+2)+1/(1+2+3)+…+1/(1+2+3+…+n)

例如:若n的值为11时,函数的值为1.833333。

注意:部分源程序给出如下。

请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

试题程序:

include <conio.h>

include <stdio.h>

include <string.h>

float fun(int n)

{

}

main()

{

int n;

float s;

clrscr();

printf("\nPlease enter N: ");

scanf("%d",&n);

s=fun(n);

printf("The result is:%f\n " , s);

}

请帮忙给出正确答案和分析,谢谢!

参考答案
您可能感兴趣的试题