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

  24、给定程序MODI1.C中 fun 函数的功能是:求

        s = aa… aa - ... - aaa - aa - a

      (此处 aa… aa 表示 n 个 a, a 和 n 的值在 1 至 9 之间)

      例如 a = 3, n = 6, 则以上表达式为:

          s = 333333 - 33333 - 3333 - 333 - 33 - 3

      其值是:296298

      a 和 n 是 fun 函数的形参,表达式的值作为函数值传回 main函数。

      请改正程序中的错误,使它能计算出正确的结果。

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

  #include

  long fun (int a, int n)

  {  int  j ;

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

     long  s = 0,  t = 1 ;

     for ( j = 0 ; j < n ; j++)

        t = t * 10 + a ;

     s = t ;

     for ( j = 1 ; j < n ; j++) {

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

       t = t % 10 ;

       s = s - t ;

     }

     return(s) ;

  }

  main( )

  {  int  a, n ;

     printf( "\nPlease enter a and n:") ;

     scanf(  "%d%d", &a, &n ) ;

     printf( "The value of  function is: %ld\n", fun ( a, n ) );

  }

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