fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int m; //fila
  6. int n; //columna
  7. int suma=0;
  8. cout<<"Suma matrices"<<endl;
  9. cout<<"Ingrese el numero de filas: "<<endl;
  10. cin>>m;
  11. cout<<"Ingrese el numero de columnas: "<<endl;
  12. cin>>n;
  13. int matriz1 [m][n];
  14. int matriz2[m][n];
  15. cout<<"Llenar matriz uno: "<<endl;
  16. for(int i=0; i<m; i++){
  17. for(int j=0; j<n; j++){
  18. cout<<"Ingrese el numero: "<<endl;
  19. cin>>matriz1[i][j];
  20. }
  21. }
  22. cout<<"Llenar matriz dos: "<<endl;
  23. for(int i=0; i<m; i++){
  24. for(int j=0; j<n; j++){
  25. cout<<"Ingrese el numero: "<<endl;
  26. cin>>matriz2[i][j];
  27. }
  28. }
  29. cout<<endl;
  30. cout<<"La matriz uno: "<<endl;
  31. for(int i=0; i<m; i++){
  32. for(int j=0; j<n; j++){
  33. cout<<matriz1[i][j] <<" ";
  34. }
  35. cout<<endl;
  36. }
  37. cout<<endl;
  38. cout<<"La matriz dos: "<<endl;
  39. for(int i=0; i<m; i++){
  40. for(int j=0; j<n; j++){
  41. cout<<matriz2[i][j] <<" ";
  42. }
  43. cout<<endl;
  44. }
  45. cout<<endl;
  46. for(int i=0; i<m; i++){
  47. for(int j=0; j<n; j++){
  48. suma=matriz1[i][j]+matriz2[i][j];
  49. }
  50. }
  51. cout<<"La suma de las matrices es: "<<suma <<endl;
  52. return 0;
  53. }
Success #stdin #stdout 0.01s 5504KB
stdin
2
2
1 2
4 6
8
9
12
13
stdout
Suma matrices
Ingrese el numero de filas: 
Ingrese el numero de columnas: 
Llenar matriz uno: 
Ingrese el numero: 
Ingrese el numero: 
Ingrese el numero: 
Ingrese el numero: 
Llenar matriz dos: 
Ingrese el numero: 
Ingrese el numero: 
Ingrese el numero: 
Ingrese el numero: 

La matriz uno: 
1 2 
4 6 

La matriz dos: 
8 9 
12 13 

La suma de las matrices es: 19