Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: Ozymxndias en 9 Mayo 2018, 19:57 pm



Título: Ayuda matriz 4x4
Publicado por: Ozymxndias en 9 Mayo 2018, 19:57 pm
hola, soy nuevo en esto de la programacion y necesito ayuda crear una funcion que solicite numeros para una matriz 4x4, luego que muestre el contenido de la matriz y que luego los sume. Alguien que me pueda ayudar?


Título: Re: Ayuda matriz 4x4
Publicado por: Yuki en 10 Mayo 2018, 01:53 am
¿Podrías mostrarnos el código que tenes hasta el momento?


Título: Re: Ayuda matriz 4x4
Publicado por: Beginner Web en 10 Junio 2018, 19:16 pm
Código
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const int FILA=4, COLUMNA=4;
  6. typedef int matriz[FILA][COLUMNA];
  7.  
  8. void cargar_matriz(matriz &n);
  9. void mostrar_matriz(matriz n);
  10. void sumar_contenido(matriz n);
  11.  
  12. int main()
  13. {
  14. matriz mi_matriz;
  15. cargar_matriz(mi_matriz);
  16. mostrar_matriz(mi_matriz);
  17. sumar_contenido(mi_matriz);
  18. system("pause");
  19. return 0;
  20. }
  21.  
  22. void cargar_matriz(matriz &n)
  23. {
  24. for(int i=0; i<FILA; i++){
  25. for(int k=0; k<COLUMNA; k++){
  26. cout << "Ingrese elemento posicion[" << i << "][" << k << "]:";
  27. cin >> n[i][k];
  28. }
  29. }
  30. }
  31.  
  32. void mostrar_matriz(matriz n)
  33. {
  34. for(int i=0; i<FILA; i++){
  35. for(int k=0; k<COLUMNA; k++){
  36. cout << "[" << n[i][k] << "]";
  37. }
  38. cout << endl;
  39. }
  40. }
  41.  
  42. void sumar_contenido(matriz n)
  43. {
  44. int suma=0;
  45. for(int i=0; i<FILA; i++){
  46. for(int k=0; k<COLUMNA; k++){
  47. suma+=n[i][k];
  48. }
  49. }
  50. cout << "Suma: " << suma << endl;
  51. }
  52.