// Calcolo della matrice trasposta #include #include #include using namespace std; //#define NR 2 //#define NC 3 int main() { int const NR=2 , NC=3 ; int NC_trasp ,NR_trasp; double A[NR][NC]; double TraspA[NC][NR]; fstream f; f.open("matrici.dat",ios::in); for (int i = 0; i < NR; i++) { for (int j = 0; j < NC; j++) { f >> A[i][j]; } } if ( f.fail() ) { cout << "Errore nell'apertura di 'matrici.dat' ==> Esco" << endl; return -1; } f.clear(); f.close(); cout << "La matrice A e`:" << endl; for (int i = 0; i < NR; i++) { for (int j = 0; j < NC; j++) { cout << A[i][j] << " "; } cout << endl; } for (int i = 0; i < NR; i++) { for (int j = 0; j < NC; j++) { TraspA[j][i]=A[i][j]; } } NR_trasp=NC; NC_trasp=NR; cout << "La matrice trasposta e`:" << endl; for (int i = 0; i < NR_trasp; i++) { for (int j = 0; j < NC_trasp; j++) { cout << TraspA[i][j] << " "; } cout << endl; } /* cout << "La matrice trasposta e`:" << endl; for (int i = 0; i < NC; i++) { for (int j = 0; j < NR; j++) { cout << A[j][i] << " "; } cout << endl; }*/ return 0; }