编写函数fun,函数的功能是:根据以下公式计算s,计算

编写函数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();
}
答案
第1空:int i, j, t;
第2空:float s=0;
第3空:i=1;i<=n;i++
第4空:t=0;
第5空:j=1;j<=i;j++
第6空:s=s+1./t;

题目信息

题号:6723
题型:填空题
知识点:计算机二级
难度:普通