java 算法题 输入一个数n,输出n阶矩阵为:如n=3,矩阵为:1 2 38 9 47 6 5如n=4,矩阵为:1 2
来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/25 11:51:46
java 算法题
输入一个数n,输出n阶矩阵为:
如n=3,矩阵为:
1 2 3
8 9 4
7 6 5
如n=4,矩阵为:
1 2 3 4
12 13 14 5
11 16 15 6
10 9 8 7
输入一个数n,输出n阶矩阵为:
如n=3,矩阵为:
1 2 3
8 9 4
7 6 5
如n=4,矩阵为:
1 2 3 4
12 13 14 5
11 16 15 6
10 9 8 7
private static void printArray(int n) {
int[][] a = new int[n][n];
int row = 0;
int col = 0;
int tempRow = 0;
int tempCol = 0;
boolean isButtom = false;
for (int i = 1; i = 0 && a[tempRow][col] == 0) {
row = tempRow;
continue;
}
}
//尝试向右
tempCol = col + 1;
if (tempCol < n && a[row][tempCol] == 0) {
col = tempCol;
isButtom = false;
continue;
}
//尝试向下
tempRow = row + 1;
if (tempRow < n && a[tempRow][col] == 0) {
row = tempRow;
isButtom = false;
continue;
}
//尝试向左
tempCol = col - 1;
if (tempCol >= 0 && a[row][tempCol] == 0) {
col = tempCol;
isButtom = true;
continue;
}
//尝试向上
tempRow = row - 1;
if (tempRow >= 0 && a[tempRow][col] == 0) {
row = tempRow;
isButtom = false;
continue;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
System.out.print(a[i][j] + "\t");
}
System.out.println();
}
}
int[][] a = new int[n][n];
int row = 0;
int col = 0;
int tempRow = 0;
int tempCol = 0;
boolean isButtom = false;
for (int i = 1; i = 0 && a[tempRow][col] == 0) {
row = tempRow;
continue;
}
}
//尝试向右
tempCol = col + 1;
if (tempCol < n && a[row][tempCol] == 0) {
col = tempCol;
isButtom = false;
continue;
}
//尝试向下
tempRow = row + 1;
if (tempRow < n && a[tempRow][col] == 0) {
row = tempRow;
isButtom = false;
continue;
}
//尝试向左
tempCol = col - 1;
if (tempCol >= 0 && a[row][tempCol] == 0) {
col = tempCol;
isButtom = true;
continue;
}
//尝试向上
tempRow = row - 1;
if (tempRow >= 0 && a[tempRow][col] == 0) {
row = tempRow;
isButtom = false;
continue;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
System.out.print(a[i][j] + "\t");
}
System.out.println();
}
}
c++ 输入n 输出n*n的数字矩阵 如 输入4输出 10 11 12 1 9 16 13 2 8 15 14 3 7
一个旋转矩阵问题同学给了我一个题目就是输入一个正整数n 比如n=4输出一个n*n的矩阵如下 1 2 3 412 13 1
C语言,输入一个(1~20)的数n!得到n*n个数,以n*n矩阵顺时针输出!
设n阶矩阵A的伴随矩阵为A* 证明:|A*|=|A|^(n-1)
编写一个Matlab函数文件,输入变量为一个n阶正定矩阵A,输出的结果为下三角矩阵L,满足A=LLT
设A,B为N阶矩阵,满足2(B^-1)A=A-4E,E为N阶单位矩阵,证明:B-2E为可逆矩阵,并求它的逆矩阵
矩阵A是元全为1的n阶矩阵(n>=2),证明A^k=n^k-1A(k是》2为正整数)
线性代数——矩阵设矩阵A为m×n矩阵,B为n阶矩阵.已知r(A)=n,试证:(1)若AB=O,则B=O(2)若AB=A,
输入一个正整数n(1≤n≤6)和n 阶矩阵a 中的元素,如果a 是上三角矩阵,输出“YES”;否则,输出“NO”
谁会矩阵的题啊,设A为n阶对称矩阵,B为n阶反对陈矩阵.证明:1、B^2(B的平方)为对称矩阵;2、AB-BA为对称矩阵
问一道线性代数证明题设矩阵A为m×n矩阵,B为n阶矩阵.已知r(A)=n,试证:(1)若AB=0,则B=0.(2)若AB
设A为n阶矩阵,证明r(A^n)=r(A^(n+1))