问题 问答题

【说明】 下面的程序用DoleRob算法生成N阶(N为奇数)魔方阵(各行、列、对角线数字之和相等)。该算法的过程为:从1开始,按如下方法依次插入各自然数,直到N2为止。 a.在第一行的正中插入1。 b.新位置应当处于最近插入位置的右上方,若该位置已超出方阵的上边界,则新位置取应选列的最下一个位置;若超出右边界,则新位置取应选行的最左一个位置。 c.若最近插入的元素是N的整数倍,则选同列的下一行位置为新位置。 例如,3阶魔方阵如下所示: 8 1 6 3 5 7 4 9 2【C程序】 #include<stdio.h> #include<stdlib.h> #define SIZE 50 main( ) { int row, col, n,value;int a[SIZE+1][SIZE+1]; /*不使用下标为0的元素*/printf("请输入要输出魔方阵的阶数n(奇数,<%d):n=",SIZE);scanf("%d",&n);if (!(n % 2)||n < 1 || (1) ) { printf("输入数据有误!\n"); exit(0);}row=1; col = (n+1)/2; value=1;while(value< = (2) ) { a[row][col] = value; /*计算下一位置*/ if(value%n !=0){row--; (3) ;if(row<1) row=n;if(col>n) (4) ; } else row++; value = (5) ;} printf("\n%d阶魔方阵如下所示:\n\n",n);for(row = 1;row <= n; row++){ for(col = 1; col <=n; col++)printf("%5d",a[row][col]); printf("\n");} }

答案

参考答案:

解析:n>SIZE,或其等价表示
(2)n*n
(3)col++,或++col,或col=col+1,或其等价表示
(4)col-=n,或col=1,或其等价表示
(5)value+l,或其等价表示

[分析]:
本题考查根据算法编写程序的基本能力。
N阶魔方阵定义为各行、列、对角线的数字之和相等。DoleRob给出了奇数阶魔方阵的算法,算法中方阵的行号和列号从1至N取值。程序中空(1)处判断n的合法性, n需为奇数,矩阵规模应不超过SIZE2
根据题中的算法描述,由于要按次序将数值1~n2放入方阵中(在程序中以value表示每次要存入的数值),因此从1开始填入。将数值填入方阵的语句为“a[row][col]= value;”,该语句在循环中,因此循环条件为“value<=n*n”,因此,空(2)处填入“n*n”。
程序中,本次填入的数值为value的值,下一次要填入的数值为value加1,因此,空(5)处应填入“value+l”。
数值1的位置在第一行的正中间,即行号为1、列号为(n+1)/2,下一个位置即2的位置在1的右上方,即1所在位置的行号减1、列号加1。当新位置超出方阵的上边界,则新位置取应选列的最下一个位置:若超出右边界,则新位置取应选行的最左一个位置,因此对于3阶魔方阵,1填入第1行第2列,2填入第3行第3列,3填入第2行第1列,其余位置按照算法步骤b类推。因此,空(3)处填入“col++”或其等价形式,空(4)处填入“col=1或“col-=n”。需要考虑的特殊情况是本次填入的value值为N的倍数时,下一个插入位置为本次插入位置的正下方,即对于3阶矩阵,4填入3的正下方,7填入6的正下方等。

完形填空
If you are writing or studying, it makes much difference where the light comes from. People use  36  and pens every day. They have to be very careful about the  37  of the light because the light shines on their work.
Every  38  gets its light either from daylight  39  the window or from the lamps,   40  no matter what kind of light it is, the way it shines is very important to the eyes.
Take a book and sit with your  41  towards the window, and try to read. Your shadow(影子) falls all over the page and makes it  42  for your eyes as if you were in a  43  room. Now turn around and face the window. The page is in shadow again,  44  the bright light is in your eyes.Try sitting with your  45  side towards the window. This is very good for reading, but if you were writing, the shadow  46  fall across the page and trouble you  47 .There is another way – sit  48  your left side to the window. Now everything is perfect for  49   as well.
Whatever kind of light is in the room, the rule about the right way to sit is  50  the same. So you see different ways to sit make much difference in writing or studying.
小题1:
A.eyesB.headsC.booksD.hands
小题2:
A.roadB.pathC.wayD.trail
小题3:
A.houseB.womanC.manD.animal
小题4:
A.fromB.throughC.intoD.inside
小题5:
A.butB.untilC.ifD.when
小题6:
A.sideB.backC.bodyD.front
小题7:
A.good B.badC.usefulD.clear
小题8:
A.brightB.cleanC.dirtyD.dark
小题9:
A.whileB.orC.ifD.till
小题10:
A.frontB.backC.leftD.right
小题11:
A.can B.mayC.has toD.ought to
小题12:
A.fewB.a fewC.littleD.a little
小题13:
A.by B.withC.againstD.near
小题14:
A.speakingB.readingC.writingD.playing
小题15:
A.onlyB.neverC.hardlyD.always
单项选择题