Ovaj program uzima matricu reda r * c od korisnika i izračunava transpoziciju matrice.
Da biste razumjeli ovaj primjer, trebali biste imati znanje o sljedećim temama programiranja na C ++:
- C ++ nizovi
- C ++ višedimenzionalni nizovi
U ovom se programu od korisnika traži da unese broj redaka i stupaca. Vrijednost redaka i stupaca u ovom programu trebala bi biti manja od 10.
Zatim se od korisnika traži da unese elemente matrice.
Program izračunava transpoziciju matrice i prikazuje je na zaslonu.
Primjer: Pronađi transpoziciju 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; )
Izlaz
Unesite retke i stupce matrice: 2 3 Unesite elemente matrice: Unesite element a11: 1 Unesite element a12: 2 Unesite element a13: 9 Unesite element a21: 0 Unesite element a22: 4 Unesite element a23: 7 Unesena matrica: 1 2 9 0 4 7 Transpozicija matrice: 1 0 2 4 9 7