当前所在位置:珠峰网资料 >> 计算机 >> 计算机等级考试 >> 正文
2015年计算机二级C语言50套程序编写上机题及答案(46)
发布时间:2011/10/31 17:54:38 来源:城市学习网 编辑:ziteng

  46、程序定义了N×N的二维数组,并在主函数中自动赋值。请编写函数fun(int a[][N], int n),函数的功能是:使数组左下三角元素中的值乘以n 。例如:若n的值为3,a 数组中的值为

       | 1 9 7 |                               | 3  9  7 |

   a = | 2 3 8 | 则返回主程序后a数组中的值应为 | 6  9  8 |

       | 4 5 6 |                               | 12 15 18|

      注意: 部分源程序存在文件PROG1.C中。

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

  #include

  #include

  #define  N  5

  void fun ( int a[][N], int n )

  {

  }

  main ( )

  {

     void

     int  a[N][N], n, i, j;

     printf("***** The array *****\n");

     for ( i =0;  i     {  for ( j =0; j       {  a[i][j] = rand(); printf( "M", a[i][j] ); }

          printf("\n");

     }

     do n = rand() ; while ( n >=3 );

     printf("n = M\n",n);

     fun ( a, n );

     printf ("***** THE  RESULT *****\n");

     for ( i =0;  i     {  for ( j =0; j        printf("\n");

     }

  }

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