Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<conio.h>
- #include<stdlib.h>
- using namespace std;
- //Funciones
- void pedir_Datos();
- void sumar_Datos(int **,int **,int,int);
- void mostrar_Datos(int **,int **,int,int);
- //Variables globales
- int **dir_Matriz1,**dir_Matriz2;
- int N_filas = 0,N_columnas = 0;
- int main(){
- //LLamada a las funciones
- pedir_Datos();
- sumar_Datos(dir_Matriz1,dir_Matriz2,N_filas,N_columnas);
- mostrar_Datos(dir_Matriz1,dir_Matriz2,N_filas,N_columnas);
- //Eliminando / liberando memoria asignada
- //Eliminando memoria en filas
- for(int i = 0; i<N_filas; i++){
- delete[] dir_Matriz1[i];
- }
- //Eliminando memoria en columnas
- delete[] dir_Matriz1;
- //Eliminando memoria en filas
- for(int i = 0; i<N_filas; i++){
- delete[] dir_Matriz2[i];
- }
- //Eliminando memoria en columnas
- delete[] dir_Matriz2;
- getch();
- return 0;
- }
- //Definiciones de funciones
- void pedir_Datos(){
- cout<<"Matriz A : "<<endl;
- cout<<" "<<endl;
- cout<<"Numero de filas : ";
- cin>>N_filas;
- cout<<"Numero de columnas : ";
- cin>>N_columnas;
- cout<<" "<<endl;
- //Asignando memoria en filas
- dir_Matriz1 = new int*[N_filas];
- //Asignando memoria en columnas
- for(int i = 0; i<N_columnas; i++){
- dir_Matriz1 = new int*[N_columnas];
- }
- //Elementos de la matriz 1
- for(int i = 0; i<N_filas; i++){
- for(int j = 0; j<N_columnas; j++){
- cout<<(j+1)<<". Matriz : ";
- cin>>*(*(dir_Matriz1+i)+j);
- }
- cout<<" "<<endl;
- }
- cout<<" "<<endl;
- cout<<"Matriz B : "<<endl;
- cout<<" "<<endl;
- cout<<"Numero de filas : ";
- cin>>N_filas;
- cout<<"Numero de columnas : ";
- cin>>N_columnas;
- //Asignando memoria en filas
- dir_Matriz2 = new int*[N_filas];
- //Asignando memoria en columnas
- for(int i = 0; i<N_columnas; i++){
- dir_Matriz2 = new int*[N_columnas];
- }
- cout<<" "<<endl;
- //Elementos de la matriz 2
- for(int i = 0; i<N_filas; i++){
- for(int j = 0; j<N_columnas; j++){
- cout<<(j+1)<<". Matriz : ";
- cin>>*(*(dir_Matriz2+i)+j);
- }
- cout<<" "<<endl;
- }
- cout<<" "<<endl;
- }
- void sumar_Datos(int **dir_Matriz1,int **dir_Matriz2,int N_filas,int N_columnas){
- for(int i = 0; i<N_filas; i++){
- for(int j = 0; j<N_columnas; j++){
- *(*(dir_Matriz1+i)+j) = *(*(dir_Matriz1+i)+j) + *(*(dir_Matriz2+i)+j);
- }
- }
- }
- void mostrar_Datos(int **dir_Matriz1,int **dir_Matriz2,int N_filas,int N_columnas){
- for(int i = 0; i<N_filas; i++){
- for(int j = 0; j<N_columnas; j++){
- cout<<*(*(dir_Matriz1+i)+j);
- }
- cout<<" "<<endl;
- }
- cout<<" "<<endl;
- }
Add Comment
Please, Sign In to add comment