Ayuda porfis.Programa que me ordene una matriz a identidad
El progrma debe pedir el tamaño de la matriz tanto filas como columnas, y los elemntos de la matriz.
No se que entiendes por "ordenar una matriz a identidad", y estoy muy curioso por saberlo.
De todas maneras te envio el programa pedido:
// program matriza.cpp
// visual c++
#include <iostream.h>
#include <iomanip.h>
const int N = 20; // diemsion maxima de la matriz 20x20
int GetNum(char *msg)
{
int num = -1;
while(num < 0 || num > N)
{
cout << setw(20) << msg;
cin >> num;
}
return num;
} // GET NUM
void GetMatrix(int a[][N],int rows,int columns)
{
cout << endl;
for(int i = 0;i < rows;i++)
{
for(int j = 0;j < columns;j++)
{
cout << "a[" << i << "," << j << "] = ";
cin >> a[i][j];
}
cout << endl;
}
cout << endl;
} // GET MATRIX
void Show(int a[][N],int rows,int columns)
{
for(int i = 0;i < rows;i++)
{
for(int j = 0;j < columns;j++)
cout << setw(5) << a[i][j];
cout << endl;
}
cout << endl << endl;
} // SHOW
void main()
{
int a[N][N],
rows = GetNum("filas = "),
columns = GetNum("columnas = ");
GetMatrix(a,rows,columns);
Show(a,rows,columns);
} // MAIN
De todas maneras te envio el programa pedido:
// program matriza.cpp
// visual c++
#include <iostream.h>
#include <iomanip.h>
const int N = 20; // diemsion maxima de la matriz 20x20
int GetNum(char *msg)
{
int num = -1;
while(num < 0 || num > N)
{
cout << setw(20) << msg;
cin >> num;
}
return num;
} // GET NUM
void GetMatrix(int a[][N],int rows,int columns)
{
cout << endl;
for(int i = 0;i < rows;i++)
{
for(int j = 0;j < columns;j++)
{
cout << "a[" << i << "," << j << "] = ";
cin >> a[i][j];
}
cout << endl;
}
cout << endl;
} // GET MATRIX
void Show(int a[][N],int rows,int columns)
{
for(int i = 0;i < rows;i++)
{
for(int j = 0;j < columns;j++)
cout << setw(5) << a[i][j];
cout << endl;
}
cout << endl << endl;
} // SHOW
void main()
{
int a[N][N],
rows = GetNum("filas = "),
columns = GetNum("columnas = ");
GetMatrix(a,rows,columns);
Show(a,rows,columns);
} // MAIN
