dynamic matrix

help please when I use void max_e_Matriz() appear very large values.

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
#include <iostream>
#include <stdlib.h>
using namespace std;
void dimMatriz(int&,int&,int **);												//Filas y Columnas entre 2 y 13;
void max_e_Matriz(int&,int&,int **);											//Buscar el elemento mayor;
int main(int argc, char *argv[]) {
	int f,c,**matriz;
	dimMatriz(f,c,matriz);
	max_e_Matriz(f,c,matriz);
	return 0;
}

void dimMatriz(int &x,int &y,int **v){
	do{
	cout<<"Filas: "<<flush;cin>>x;
	cout<<"Columnas: "<<flush;cin>>y;}while(x<2 || x>13 && y<2 || y>13 );
	v=new int *[x];
	for(int i=0;i<y;i++){v[i]=new int[y];}
	for(int i=0;i<x;i++){for(int j=0;j<y;j++){
	*(*(v+i)+j)=rand()%10;
	cout<<*(*(v+i)+j)<<" ";
	}cout<<endl;}
}

void max_e_Matriz(int &a,int &b,int **v){
cout<<endl<<"Matriz a la izquierda: "<<endl;
for(int x=0;x<a;x++){for(int y=0;y<b;y++){
cout<<*(*(v+x)+y)<<" ";}cout<<endl;}
}
consider using [] notation.

for(x = 0; x < a; x++)
for(y = 0; y < b; y++)
{
cout << v[x][y] << endl;
//if this gives trouble, look into dimMatriz to ensure that is correct, and write out a and b to check those.
}

also consider using a vector.
Last edited on
Topic archived. No new replies allowed.