填空题

编写函数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();

}

赣ICP备20007335号-2