当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
2015年计算机二级C语言50套程序修改上机题(22)
发布时间:2011/11/1 9:58:40 来源:城市学习网 编辑:ziteng

  22、给定程序MODI1.C中fun函数的功能是: 根据整型形参m,计算如下公式的值。

                  1       1              1

        t = 1 - ----- - ----- - …… - -----

                  2       3              m

      例如,若主函数中输入5,则应输出 -0.283333。

      请改正函数fun中的错误或在横线处填上适当的内容并把横线删除, 使它能计算出正确的结果。

      注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构!

  #include

  double fun( int m )

  {

    double t = 1.0;

    int i;

    for( i = 2; i <= m; i++ )

  /**********found**********/

      t = 1.0-1 /i;

  /**********found**********/

     _______;

  }

  main()

  {

    int m ;

    printf( "\nPlease enter 1 integer numbers:\n" );

    scanf(  "%d", &m);

    printf( "\n\nThe result is %lf\n", fun( m ) );

  }

广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved