欢迎来到天天文库
浏览记录
ID:19640521
大小:73.00 KB
页数:6页
时间:2018-10-04
《基于c语言和java螺旋方阵》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、编程序,显示螺旋方阵: 1 2 3 4 12 13 14 5 11 16 15 6 10 9 8 7 #include#definemax10intmain(){intsquare[max][max];inti,j,k=1,d=0,n;//d为操作向量printf("请输入螺旋方阵的阶数n:");scanf("%d",&n);if(n>max){printf("阶数超过最大值max");printf("");printf("Pleasetryagain"
2、);printf("");}else{for(i=0;i3、]==0)i++;/*实现行递加*/elsed=2,j--;break;case2:if(0<=i&&i4、);printf("t");}printf("");}}return0;}packagejava7;importjava.util.Scanner;publicclasstest5{publicstaticvoidmain(String[]args){intsquare[][]=newint[20][20];inti,j,k=1,d=0;//d为操作向量System.out.print("请输入螺旋方阵的阶数n:");Scannersin=newScanner(System.in);intn=sin.nextInt();if(n>20){System.out.print("阶数超过5、最大值");System.out.print("Pleasetryagain");}else{for(i=0;i6、&&0<=j&&j7、++){System.out.print(""+square[i][j]);System.out.print('t');}System.out.println();}}}
3、]==0)i++;/*实现行递加*/elsed=2,j--;break;case2:if(0<=i&&i4、);printf("t");}printf("");}}return0;}packagejava7;importjava.util.Scanner;publicclasstest5{publicstaticvoidmain(String[]args){intsquare[][]=newint[20][20];inti,j,k=1,d=0;//d为操作向量System.out.print("请输入螺旋方阵的阶数n:");Scannersin=newScanner(System.in);intn=sin.nextInt();if(n>20){System.out.print("阶数超过5、最大值");System.out.print("Pleasetryagain");}else{for(i=0;i6、&&0<=j&&j7、++){System.out.print(""+square[i][j]);System.out.print('t');}System.out.println();}}}
4、);printf("t");}printf("");}}return0;}packagejava7;importjava.util.Scanner;publicclasstest5{publicstaticvoidmain(String[]args){intsquare[][]=newint[20][20];inti,j,k=1,d=0;//d为操作向量System.out.print("请输入螺旋方阵的阶数n:");Scannersin=newScanner(System.in);intn=sin.nextInt();if(n>20){System.out.print("阶数超过
5、最大值");System.out.print("Pleasetryagain");}else{for(i=0;i6、&&0<=j&&j7、++){System.out.print(""+square[i][j]);System.out.print('t');}System.out.println();}}}
6、&&0<=j&&j7、++){System.out.print(""+square[i][j]);System.out.print('t');}System.out.println();}}}
7、++){System.out.print(""+square[i][j]);System.out.print('t');}System.out.println();}}}
此文档下载收益归作者所有