Program C ++ za iskanje transpozicije matrike

Ta program od uporabnika vzame matrico vrstnega reda r * c in izračuna prenos matrike.

Če želite razumeti ta primer, morate poznati naslednje programske teme C ++:

  • Polja C ++
  • Večdimenzionalni nizi C ++

V tem programu je uporabnik pozvan, da vnese število vrstic in stolpcev. Vrednost vrstic in stolpcev mora biti v tem programu manjša od 10.

Nato uporabnika prosimo, da vnese elemente matrike.

Program izračuna prenos matrice in jo prikaže na zaslonu.

Primer: Poiščite prenos matrike

 #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; )

Izhod

 Vnesite vrstice in stolpce matrike: 2 3 Vnesite elemente matrike: Vnesite element a11: 1 Vnesite element a12: 2 Vnesite element a13: 9 Vnesite element a21: 0 Vnesite element a22: 4 Vnesite element a23: 7 Vnesena matrica: 1 2 9 0 4 7 Prenos matrike: 1 0 2 4 9 7 

Zanimive Članki...