{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

matrix transpose

# matrix transpose - cout<< endl<<"Transpose...

This preview shows page 1. Sign up to view the full content.

#include <cstdlib> #include <iostream> using namespace std; void matrixTranspose(float **M, int n); int main(int argc, char *argv[]) { float M[4][4] = { {11,12,13,14}, {21,22,23,24}, {31,32,33,34}, {41,42,43,44} }; int i,j, n = 4; float ** pm; pm = new float *[n]; // allocate n row pointers for(i = 0; i < n; i++) pm[i] = M[i]; // allocate the ith row cout << "Initial: M[" << n << "][" << n << "]" << endl; for(i = 0; i < n; i++) { for(j = 0; j < n; j++) cout << " " << pm[i][j] << " "; cout << endl; } matrixTranspose(pm, n);
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cout << endl << "Transpose: M[" << n << "][" << n << "]" << endl; for(i = 0; i < n; i++) { for(j = 0; j < n; j++) cout << " " << pm[i][j] << " "; cout << endl; } system("PAUSE"); return EXIT_SUCCESS; } void matrixTranspose(float **M, int n) { for(int i = 0; i < n-1; i++) // start with 1st row to the (n-1)th row for(int j = i+1; j < n; j++) // start with 2nd column to the nth column swap(M[i][j],M[j][i]); // t = M[i][j]; // M[i][j] = M[j][i]; // M[j][i] = t; }...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online