有以下程序 #include <stdio.h> #define N 4 void fun(int a[][N]) { int b[N][N],i,j; for(i=0; i<N; i++) for(j=0; j<N; j+

admin2021-02-25  14

问题 有以下程序
#include <stdio.h>
#define  N    4
void fun(int a[][N])
{  int  b[N][N],i,j;
   for(i=0; i<N; i++)
      for(j=0; j<N; j++)
         b[j] = a[N-1-j];
   for(i=0; i<N; i++)
      for(j=0; j<N; j++)
         a[j] = b[j];
}
main()
{  int  x[N][N]={ {1, 2, 3, 4},
               {5, 6, 7, 8},
               {9,10,11,12},
               {13,14,15,16}}, i;
   fun(x);
   for (i=0;i<N; i++)
       printf("%d,", x);
   printf("\n");
}
程序的运行结果是

选项 A、13,10,7,4,
B、1,6,11,16,
C、4,7,10,13,
D、1,5,9,13,

答案A

解析 函数调用中,将数组名作为参数,将数组地址传给形参,所以函数中对数组a的操作将会改变x数组元素值。函数实现将原数组列变成行,再将每一行首尾倒置,此时数组a(也即x)中元素为{{13,9,5,1},{14,10,6,2},{15,11,7,3},{16,12,8,4}},则输出13,10,7,4,A选项正确。
转载请注明原文地址:https://kaotiyun.com/show/VBtp777K
0

最新回复(0)