// 2a.cpp
#include <iostream>
using namespace std;
void leerDimensiones(int &nfil, int &ncol);
double **reservaMemoriaMat(int f, int c);
void llenarMatriz(double **p, int f, int c);
void mostrarMatriz(double **p, int f, int c);
double minMax(double **p, int f, int c);
void liberarMemoriaMat(double **matriz, int f, int c);
int main(){
int f, c, min1, min2;
double **m1,**m2; //declaracion
cout<<"Primera Matriz\n";
leerDimensiones(f, c);
m1 = reservaMemoriaMat(f, c);
m2 = reservaMemoriaMat(f, c);
llenarMatriz(m1, f, c);
llenarMatriz(m2, f, c);
//Presentacion de datos
cout<<"Valores insertados en la matriz 1\n";
mostrarMatriz(m1,f,c);
cout<<"Valores insertados en la matriz 2\n";
mostrarMatriz(m2, f, c);
min1 = minMax(m1, f, c);
min2 = minMax(m2, f, c);
if (min1<min2)
cout<<"El menor minmax es "<<min1<<" y esta en la primera matriz\n";
else
cout<<"El menor minmax es "<<min2<<" y esta en la segunda matriz\n";
liberarMemoriaMat(m1, f, c);
liberarMemoriaMat(m2, f, c);
}
double minMax(double **p, int f, int c){
double minmax,aux;
for (int i=0;i<f;i++){
aux=p[i][1];
for (int j=1;j<c;j++)
if(aux<p[i][j])
aux= p[i][j];
if(i==0)
minmax=aux;
else
if(aux<minmax)
minmax=aux;
}
return minmax;
}
void liberarMemoriaMat(double **matriz, int f, int c){
for (int i=0;i<f;i++)
delete[] matriz[i];
delete[] matriz;
cout<<"Se libero memoria\n";
}
double **reservaMemoriaMat(int f, int c){
double **aux;
//inicializacion
aux = new double*[f];
for (int i=0;i<f;i++)
aux[i] = new double[c];
return aux;
}
void leerDimensiones(int &nfil, int &ncol){
cout<<"Numero de filas= ";
cin>>nfil;
cout<<"Numero de columnas= ";
cin>>ncol;
}
void mostrarMatriz(double **p, int f, int c){
for (int i=0; i<f; i++){
for (int j=0; j<c; j++)
cout<<p[i][j]<<" ";
cout<<endl;
}
}
void llenarMatriz(double **p, int f,int c){
cout<<"Ingreso de datos por fila\n";
for(int i=0; i<f; i++){
cout<<"Fila "<<i+1<<": ";
for (int j=0;j<c;j++)
cin>>p[i][j];
cout<<endl;
}
}