编制一个程序,求10´10矩阵A的转置矩阵AT,即 要求确定两组初值,运行设计的程序,显示或打印每一组的A和AT。
时间: 2023-04-03 12:05:07 浏览: 86
求矩阵转置
可以使用以下程序来求解10´10矩阵A的转置矩阵AT:
#include <stdio.h>
#define ROWS 10
#define COLS 10
void transpose(int A[][COLS], int AT[][ROWS]) {
int i, j;
for (i = 0; i < ROWS; i++) {
for (j = 0; j < COLS; j++) {
AT[j][i] = A[i][j];
}
}
}
int main() {
int A[ROWS][COLS] = {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
{11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
{21, 22, 23, 24, 25, 26, 27, 28, 29, 30},
{31, 32, 33, 34, 35, 36, 37, 38, 39, 40},
{41, 42, 43, 44, 45, 46, 47, 48, 49, 50},
{51, 52, 53, 54, 55, 56, 57, 58, 59, 60},
{61, 62, 63, 64, 65, 66, 67, 68, 69, 70},
{71, 72, 73, 74, 75, 76, 77, 78, 79, 80},
{81, 82, 83, 84, 85, 86, 87, 88, 89, 90},
{91, 92, 93, 94, 95, 96, 97, 98, 99, 100}};
int AT[COLS][ROWS];
int i, j;
transpose(A, AT);
printf("矩阵A:\n");
for (i = 0; i < ROWS; i++) {
for (j = 0; j < COLS; j++) {
printf("%d ", A[i][j]);
}
printf("\n");
}
printf("\n转置矩阵AT:\n");
for (i = 0; i < COLS; i++) {
for (j = 0; j < ROWS; j++) {
printf("%d ", AT[i][j]);
}
printf("\n");
}
return 0;
}
你可以输入两组不同的初值来运行程序,显示或打印每一组的A和AT。
阅读全文