C ++程序查找图矩阵的转置
在此程序中,我们采用矩阵并打印矩阵的转置。在转置矩阵中,行变为列,反之亦然。
算法
Begin Take number of rows and columns of the matrix. Take The elements of the matrix and stored in the matrix ‘A’. The transpose matrix is found by exchanging the rows with columns and columns with rows. Print both the original matrix and the transpose. End.
范例程式码
#include<iostream>
using namespace std;
int main () {
int A[10][10], a, b, i, j;
cout << "Enter rows and columns of matrix : ";
cin >> a>> b;
cout << "Enter elements of matrix : ";
for (i = 0; i < a; i++)
for (j = 0; j < b; j++)
cin >> A[i][j];
cout << "Entered Matrix : \n ";
for (i = 0; i < a; i++) {
for (j = 0; j < b; j++)
cout << A[i][j] << " ";
cout << "\n ";
}
cout << "Transpose of Matrix : \n ";
for (i = 0; i < b;) {
for (j = 0; j < a; j++)
cout << A[j][i] << " ";
cout << "\n ";
}
return 0;
}输出结果
Enter rows and columns of matrix:3 3 Enter elements of matrix : 6 7 1 3 2 5 9 12 11 Entered Matrix : 6 7 1 3 2 5 9 12 11 Transpose of Matrix : 6 3 9 7 2 12 1 5 11
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短