Calcul matriciel en c++: Calculer la transposée d'une matrice
Programme qui fait la transposition tA(M,N) d'une matrice A(N,M) de dimension.
using namespace std; #include<stdio.h> #include<stdlib.h> #include <iostream> int** transposee (int** A, int N, int M) { int** tA = new int* [ M ]; for (int i=0; i < M; i++) tA[i] = new int[ N ]; for(int i = 0; i < N; i++) { for(int j = 0; j < M; j++) { tA[j][i]=A[i][j]; } } return tA; } void affichage(int** Mat, int N, int M){ for(int i = 0; i < N; i++) { for(int j = 0; j < M; j++) { cout << Mat[i][j] ; cout << "\t"; } cout << "\n"; } cout << "\n"; } main() int N=2,M=3; int** A = new int* [ N ]; for (int i=0; i < N; i++) A[i] = new int[ M ]; A[0][0]=1;A[0][1]=2;A[0][2]=3; A[1][0]=4;A[1][1]=5;A[1][2]=6; affichage(A,N,M); int** tA = new int* [ M ]; for (int i=0; i < M; i++) tA[i] = new int[ N ]; tA = transposee(A,N,M); cout << "Matrice transposee\n"; affichage(tA,M,N); return 0; } |