Guest User

Untitled

a guest
Jul 18th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. #include<iostream>
  2. #include<conio.h>
  3. #include<stdlib.h>
  4.  
  5. using namespace std;
  6.  
  7. //Funciones
  8.  
  9. void pedir_Datos();
  10. void sumar_Datos(int **,int **,int,int);
  11. void mostrar_Datos(int **,int **,int,int);
  12.  
  13. //Variables globales
  14.  
  15. int **dir_Matriz1,**dir_Matriz2;
  16. int N_filas = 0,N_columnas = 0;
  17.  
  18. int main(){
  19. //LLamada a las funciones
  20.  
  21. pedir_Datos();
  22. sumar_Datos(dir_Matriz1,dir_Matriz2,N_filas,N_columnas);
  23. mostrar_Datos(dir_Matriz1,dir_Matriz2,N_filas,N_columnas);
  24.  
  25. //Eliminando / liberando memoria asignada
  26.  
  27. //Eliminando memoria en filas
  28. for(int i = 0; i<N_filas; i++){
  29. delete[] dir_Matriz1[i];
  30. }
  31.  
  32. //Eliminando memoria en columnas
  33. delete[] dir_Matriz1;
  34.  
  35.  
  36. //Eliminando memoria en filas
  37. for(int i = 0; i<N_filas; i++){
  38. delete[] dir_Matriz2[i];
  39. }
  40.  
  41. //Eliminando memoria en columnas
  42. delete[] dir_Matriz2;
  43.  
  44. getch();
  45. return 0;
  46. }
  47.  
  48. //Definiciones de funciones
  49.  
  50. void pedir_Datos(){
  51. cout<<"Matriz A : "<<endl;
  52. cout<<" "<<endl;
  53.  
  54. cout<<"Numero de filas : ";
  55. cin>>N_filas;
  56.  
  57. cout<<"Numero de columnas : ";
  58. cin>>N_columnas;
  59.  
  60. cout<<" "<<endl;
  61.  
  62. //Asignando memoria en filas
  63. dir_Matriz1 = new int*[N_filas];
  64. //Asignando memoria en columnas
  65. for(int i = 0; i<N_columnas; i++){
  66. dir_Matriz1 = new int*[N_columnas];
  67. }
  68.  
  69. //Elementos de la matriz 1
  70.  
  71. for(int i = 0; i<N_filas; i++){
  72. for(int j = 0; j<N_columnas; j++){
  73. cout<<(j+1)<<". Matriz : ";
  74. cin>>*(*(dir_Matriz1+i)+j);
  75. }
  76. cout<<" "<<endl;
  77. }
  78. cout<<" "<<endl;
  79.  
  80. cout<<"Matriz B : "<<endl;
  81. cout<<" "<<endl;
  82.  
  83. cout<<"Numero de filas : ";
  84. cin>>N_filas;
  85.  
  86. cout<<"Numero de columnas : ";
  87. cin>>N_columnas;
  88.  
  89. //Asignando memoria en filas
  90. dir_Matriz2 = new int*[N_filas];
  91. //Asignando memoria en columnas
  92. for(int i = 0; i<N_columnas; i++){
  93. dir_Matriz2 = new int*[N_columnas];
  94. }
  95.  
  96. cout<<" "<<endl;
  97.  
  98. //Elementos de la matriz 2
  99.  
  100. for(int i = 0; i<N_filas; i++){
  101. for(int j = 0; j<N_columnas; j++){
  102. cout<<(j+1)<<". Matriz : ";
  103. cin>>*(*(dir_Matriz2+i)+j);
  104. }
  105. cout<<" "<<endl;
  106. }
  107. cout<<" "<<endl;
  108. }
  109.  
  110. void sumar_Datos(int **dir_Matriz1,int **dir_Matriz2,int N_filas,int N_columnas){
  111. for(int i = 0; i<N_filas; i++){
  112. for(int j = 0; j<N_columnas; j++){
  113. *(*(dir_Matriz1+i)+j) = *(*(dir_Matriz1+i)+j) + *(*(dir_Matriz2+i)+j);
  114. }
  115. }
  116. }
  117.  
  118. void mostrar_Datos(int **dir_Matriz1,int **dir_Matriz2,int N_filas,int N_columnas){
  119. for(int i = 0; i<N_filas; i++){
  120. for(int j = 0; j<N_columnas; j++){
  121. cout<<*(*(dir_Matriz1+i)+j);
  122. }
  123. cout<<" "<<endl;
  124. }
  125. cout<<" "<<endl;
  126. }
Add Comment
Please, Sign In to add comment