Created
June 18, 2013 02:30
-
-
Save xyos/5802224 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# include <iostream> | |
# include <cstdlib> | |
# include <fstream> | |
using namespace std; | |
double ** crear_matriz (int n, int m) | |
{ | |
double ** X=new double*[n]; | |
for (int i=0; i<n; i++) | |
{ | |
X[i]=new double [m]; | |
} | |
return X; | |
} | |
void liberar_matriz_double(double ** X, int n ,int m) | |
{ | |
for (int i=0; i<n;i++) | |
{ | |
delete[] X[i]; | |
} | |
delete[]X; | |
return; | |
} | |
double ** leer_matriz_double(istream& is, double** X, int n, int m) | |
{ | |
for (int i=0; i<n ; i++) | |
{ | |
for (int j=0; j<m; j++) | |
{ | |
is >> X[i][j]; | |
} | |
} | |
return X; | |
} | |
ostream & escribir_matriz_double(ostream& os, double** X,int n, int m) | |
{ | |
for (int i=0; i<n; i++) | |
{ | |
for (int j=0; j<m; j++) | |
{ | |
os<< X[i][j]; | |
if (j<m-1) | |
{ | |
os<<"\t"; | |
} | |
} | |
os<<"\n"; | |
} | |
return os; | |
} | |
double **trasponer_matriz(double ** X, double ** Y , int n, int m) | |
{ | |
for (int i=0; i<n ; i++) | |
{ | |
for (int j=0; j<m; j++) | |
{ | |
Y[i][j]=X[j][i]; | |
} | |
} | |
return Y; | |
} | |
int main() | |
{ | |
int n,m; | |
cout<<"Ingrese el tamaño de la matriz cuadrdada"<<endl; | |
cout<<"filas: "; | |
cin>>n; // lee el tamaño de la matriz previa mente creada y almacenada en la misma carpeta del programa | |
cout<<"Columnas: "; | |
cin>>m; // lee el tamaño de la matriz previa mente creada y almacenada en la misma carpeta del programa | |
ifstream ifs("matriz_a_leer.txt"); | |
ofstream ofs("matriz_traspuesta.txt"); | |
double**X=crear_matriz(n,m); | |
double**Y=crear_matriz(m,n); | |
X=leer_matriz_double(ifs,X,n,m); | |
cout<<"Matriz original: "<<endl; | |
escribir_matriz_double(cout,X,n,m); | |
cout<<"Matriz traspuesta"<<endl; | |
Y=trasponer_matriz(X,Y,m,n); | |
escribir_matriz_double(cout,Y,m,n); | |
escribir_matriz_double(ofs,Y,m,n); | |
cout<<"\nLa matriz tambien se ha guardado como: 'matriz_traspuesta.txt'"<<endl; | |
liberar_matriz_double(X, n, m); | |
liberar_matriz_double(Y, m, n); | |
ifs.close(); | |
ofs.close(); | |
system("PAUSE"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment