1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <time.h>
using namespace std;
void Dimensionar2D(vector<vector<int> > &v,int &,int &);
void Rellenar2D(vector<vector<int> > &,int &,int &);
void Observar2D(vector<vector<int> > &);
int BuscarM2D(vector<vector<int> > &);
int main(int argc, char *argv[]) {
vector<vector<int> > matriz;
int F=0,C=0;
Dimensionar2D(matriz,F,C);
Rellenar2D(matriz,F,C);
Observar2D(matriz);
cout<<"El mayor es: "<<BuscarM2D(matriz)<<endl;
return 0;
}
void Dimensionar2D(vector<vector<int> > &v,int &a,int &b){
while(a<2 || a>13 && b<2 || b>13){
cout<<"Filas: "<<flush;cin>>a;
cout<<"Columnas: "<<flush;cin>>b;
cout<<endl;
}}
void Rellenar2D(vector<vector<int> >&v,int &a,int &b){
vector<int> temp;
srand (time(NULL));
for(int x=0;x<a;x++){
for(int y=0;y<b;y++){
temp.push_back(rand()%10);}
v.push_back(temp);temp.clear();}
}
void Observar2D(vector<vector<int> > &v){
for(int x=0;x<v.size();x++){
for(int y=0;y<v[y].size();y++){cout<<v[x][y]<<" "<<flush;}
cout<<endl;}
}
int BuscarM2D(vector<vector<int> > &v){
int actual=0,mayor=0;
for(int x=0;x<v.size();x++){
for(int y=0;y<v[y].size()-1;y++){actual=v[x][y];
if(actual>mayor){mayor=actual;}}}
return(mayor);
}
|