Anda di halaman 1dari 2

Ejercicios_AB_03

#include <iostream>
using namespace std;
const int MAX=100;
void LeeDatosMatriz(int datos[][MAX], int n, int m)
{
cout<<"Ingrese "<<m<<" datos por fila: "<<endl;
for (int f=0; f<n; f++)
{
for (int c=0; c<m; c++)
cin>>datos[f][c]; }}
void PrintMatriz(int datos[MAX][MAX], int n, int m)
{
cout<<"\nDatos de la matriz:\n";
for (int f=0; f<n; f++)
{
for (int c=0; c<m; c++)
cout<<datos[f][c]<<"\t";
cout<<endl;
}
cout<<endl;
}
void PromedioXfilas(int datos[MAX][MAX], int n, int m)
{
float suma;
for (int f=0; f<n; f++)
{ suma = 0.0;
for (int c=0; c<m; c++)
suma += datos[f][c];
cout<<"Promedio fila "<<f<<" = "<<(suma/m)<<endl;
}
}
void PromedioXcolumnas(int datos[MAX][MAX], int n, int m)
{
float suma;
for (int c=0; c<m; c++)
{ suma = 0.0;
for(int f=0; f<n; f++)
suma += datos[f][c];
cout<<"Promedio columna "<<c<<" = "<<(suma/n)<<endl;
}
}
void SumaMatriz(int m1[MAX][MAX],int m2[MAX][MAX],int s[MAX][MAX],int n,int m)
{
for (int f = 0; f<n; f++)
{
for (int c=0; c<m; c++)
s[f][c] = m1[f][c] + m2[f][c];
}

Ejercicios_AB_03
}
void TrasponerMatriz(int m1[MAX][MAX],int t[MAX][MAX],int n,int m)
{
for (int f = 0; f<n; f++)
{
for (int c=0; c<m; c++)
t[c][f] = m1[f][c];
}
}
#endif // MATRIZ2_H
#include <iostream>
#include "matriz2.h"
using namespace std;
int main()
{
int mat[MAX][MAX];
int n, m;
cout<<"Ingrese el orden nxm de la matriz: ";
cin >> n >> m;
LeeDatosMatriz(mat, n, m);
PrintMatriz(mat, n, m);
PromedioXfilas(mat, n, m);
PromedioXcolumnas(mat, n, m);
int mat2[MAX][MAX];
if (n == m)
{
TrasponerMatriz(mat, mat2,n,m);
cout<<"\nMatriz traspuesta: "<<endl;
PrintMatriz(mat2,n,m);
}else
cout<<"Definido solo para matrices cuadradas!..."<<endl;
/* Ejercicio:
Modifique la funcion TransponerMatriz de forma tal que permita
trasponer una matriz no cuadrada.
*/
return 0;
}

Anda mungkin juga menyukai