阅读以下说明及C++程序代码,将应填入(n)处的语句写在对应栏内。【说明】本程序的功能是生成螺旋方阵,用户可以输入该方阵的行列数,然后就生成对应的螺旋方阵。例如:当n=5时,对应的螺旋方阵如下:1 16 15 14 132 17 24 23 123 18 25 22 114 19 20 21 105 6 7 8 9【C++代码】include"stdio.h"include"iostream,h"int array[11][11];int temp;int ROW;void godown(int m,int a){for(temp=1; temp<=ROW;temp++)if(array[temp][a]==0)array[temp][a]=(1);a++;}void goright(int m,int b){for(temp=1;temp<=ROW;temp++)if(array[b][temp]==0)array[b][temp]=m++;b--;}void goup(int m.int c){for(temp=ROW;temp>0;temp-)if(array[temp][c]==0)array[temp][c]=m++;c--;}void goleft(int m,int d){for(temp=ROW;temp>0;temp--)if(array[d][temp]==0)array[d][temp]=m++;(2);}void main(){int a,b,c,d,max,m;cin>>ROW;cout>>end1;for(a=1;a<=ROW;a++)for(b=1;b<=ROW;b++)(3);m=1;a=d=1;b=c=ROW;max=(4);whiie(m<=max){godown(m,a);(5) (m,b);goup(m,c);goleft(m,d):}for(a=1;a<=ROW;a++){for(b=1;b<=ROW;b++)printf("%3d ",array[a][b]);cout<<end1;}}

阅读以下说明及C++程序代码,将应填入(n)处的语句写在对应栏内。

【说明】

本程序的功能是生成螺旋方阵,用户可以输入该方阵的行列数,然后就生成对应的螺旋方阵。例如:当n=5时,对应的螺旋方阵如下:

1 16 15 14 13

2 17 24 23 12

3 18 25 22 11

4 19 20 21 10

5 6 7 8 9

【C++代码】

include"stdio.h"

include"iostream,h"

int array[11][11];

int temp;

int ROW;

void godown(int &m,int &a)

{

for(temp=1; temp<=ROW;temp++)

if(array[temp][a]==0)

array[temp][a]=(1);

a++;

}

void goright(int &m,int &b)

{

for(temp=1;temp<=ROW;temp++)

if(array[b][temp]==0)

array[b][temp]=m++;

b--;

}

void goup(int &m.int &c)

{

for(temp=ROW;temp>0;temp-)

if(array[temp][c]==0)

array[temp][c]=m++;

c--;

}

void goleft(int &m,int &d)

{

for(temp=ROW;temp>0;temp--)

if(array[d][temp]==0)

array[d][temp]=m++;

(2);

}

void main()

{

int a,b,c,d,max,m;

cin>>ROW;

cout>>end1;

for(a=1;a<=ROW;a++)

for(b=1;b<=ROW;b++)

(3);

m=1;

a=d=1;

b=c=ROW;

max=(4);

whiie(m<=max)

{

godown(m,a);

(5) (m,b);

goup(m,c);

goleft(m,d):

}

for(a=1;a<=ROW;a++)

{

for(b=1;b<=ROW;b++)

printf("%3d ",array[a][b]);

cout<<end1;

}

}


相关考题:

阅读以下说明及Visual Basic程序代码,将应填入(n)处的字句写在对应栏内。【说明】以下程序为求行列式X(5,5)的值S。【Visual Basic代码】Private Function col ( byval x ( 5,5 ) as integer ) as longdim fesult as longdim temp as longdim I as integerdim j as integerdim k as imegerresult = 0for I = to 5(1)for j = 1 to 5if I+j>6 thenk= ( 1+j ) mod 5elsek=1endiftemp=temp*x ( k,j )(2)result=(3)(4)(5)End function

阅读以下说明和c++码,将应填入(n)处的字名写在的对应栏内。[说明] 以下函数完成求表达式的值,请填空使之完成此功能。float sum ( float x ){ float s=0.0;int sign = 1;(1);for(inti=1;(2); i+ +){t=t*x;s=s+(3);sign = - sign;(4);}

阅读下列说明和流程图,将应填入(n)处的语句写在对应栏内。【说明】下列流程图用泰勒(Taylor)展开式y=ex=1+x+x2/2!+x3/3!+…+xn/n!+…计算并打印ex的近似值,其中用ε(>0)表示误差要求。【流程图】

阅读以下说明,以及用C++在开发过程中所编写的程序代码,将应填入(n)处的字句写在对应栏内。【说明】在下面函数横线处填上适当的字句,使其输出结果为:构造函数.构造函数.1,25,6析构函数析构函数.【C++代码】include "iostream.h"class AA{ public;AA(int i,int j){A=i; B=j;cout<<"构造函数.\n";}~AA(){(1);}void print();private:int A, B;};void AA∷print(){cout<<A<<","<<B<<endl;}void main(){AA *a1, *a2;(2)=new AA(1, 2);a2=new AA(5, 6);(3);a2->print();(4) a1;(5) a2;}

阅读下列程序说明和C++程序,把应填入其中(n)处的字句,写在对应栏内。【说明】阅读下面几段C++程序回答相应问题。比较下面两段程序的优缺点。①for (i=0; i<N; i++ ){if (condition)//DoSomething…else//DoOtherthing…}②if (condition) {for (i =0; i<N; i++ )//DoSomething}else {for (i=0; i <N; i++ )//DoOtherthing…}

试题三(共 15 分)阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。

()阅读下列说明和C语言程序,将应填入 (n)处的语句写在答题纸的对应栏内。[说明]下面程序是一个带参数的主函数,其功能是显示在命令行中输入的文本文件内容。[C语言函数]#include"stdio.h"main(argc,argv) int argc; char *argv[]; { (1) ; if((fp=fopen(argv[1],”r’’))== (2) ) { printf(”file not open!\n”);exit(0);} while( (3) ) putchar( (4) ); (5); }

阅读下列说明和C++-代码,将应填入(n)处的字句写在答题纸的对应栏内。 【说明】 某发票(lnvoice)由抬头(Head)部分、正文部分和脚注(Foot)部分构成。现采用装饰(Decorator)模式实现打印发票的功能,得到如图5-1所示的类图。【C++代码】 #include using namespace std; class invoice{ public: (1){ cout

阅读下列说明和?C++代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】阅读下列说明和?Java代码,将应填入?(n)?处的字句写在答题纸的对应栏内。【说明】某快餐厅主要制作并出售儿童套餐,一般包括主餐(各类比萨)、饮料和玩具,其餐品种类可能不同,但其制作过程相同。前台服务员?(Waiter)?调度厨师制作套餐。现采用生成器?(Builder)?模式实现制作过程,得到如图?6-1?所示的类图。