Acest program ia o matrice de ordinul r * c de la utilizator și calculează transpunerea matricei.
Pentru a înțelege acest exemplu, ar trebui să aveți cunoștințele următoarelor subiecte de programare C ++:
- Matrice C ++
- Matrice multidimensionale C ++
În acest program, utilizatorul este rugat să introducă numărul de rânduri și coloane. Valoarea rândurilor și coloanelor ar trebui să fie mai mică de 10 în acest program.
Apoi, utilizatorul este rugat să introducă elemente ale matricei.
Programul calculează transpunerea matricei și o afișează pe ecran.
Exemplu: Găsiți transpunerea unei matrice
#include using namespace std; int main() ( int a(10)(10), transpose(10)(10), row, column, i, j; cout <> row>> column; cout << "Enter elements of matrix: " << endl; // Storing matrix elements for (int i = 0; i < row; ++i) ( for (int j = 0; j < column; ++j) ( cout << "Enter element a" << i + 1 << j + 1 <> a(i)(j); ) ) // Printing the a matrix cout << "Entered Matrix: " << endl; for (int i = 0; i < row; ++i) ( for (int j = 0; j < column; ++j) ( cout << " " << a(i)(j); if (j == column - 1) cout << endl << endl; ) ) // Computing transpose of the matrix for (int i = 0; i < row; ++i) for (int j = 0; j < column; ++j) ( transpose(j)(i) = a(i)(j); ) // Printing the transpose cout << "Transpose of Matrix: " << endl; for (int i = 0; i < column; ++i) for (int j = 0; j < row; ++j) ( cout << " " << transpose(i)(j); if (j == row - 1) cout << endl << endl; ) return 0; )
Ieșire
Introduceți rândurile și coloanele matricei: 2 3 Introduceți elementele matricei: Introduceți elementul a11: 1 Introduceți elementul a12: 2 Introduceți elementul a13: 9 Introduceți elementul a21: 0 Introduceți elementul a22: 4 Introduceți elementul a23: 7 Introduceți matricea: 1 2 9 0 4 7 Transpunerea matricei: 1 0 2 4 9 7