elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado:


  Mostrar Temas
Páginas: [1]
1  Programación / .NET (C#, VB.NET, ASP) / sumar filas y columnas en c# en: 29 Octubre 2016, 02:48 am
tengo que sumar los elementos de cada fila y cada columna de una matriz

esto es lo que llevo hasta el momento

    
Código
  1.       int M, N;
  2.            double suma = 0;
  3.  
  4.            Console.Write("filas: ");
  5.            N = int.Parse(Console.ReadLine());
  6.            Console.Write("columnas: ");
  7.            M = int.Parse(Console.ReadLine());
  8.  
  9.            int[][] matriz = new int[M][N]; <-------AQUI ME MARCA ERROR EN LA N
  10.  
  11.            for (int f = 0; f < matriz.Length; f++)
  12.            {
  13.                for (int c = 0; c < matriz[f].Length; c++)
  14.                {
  15.                    Console.Write("ingrese valores: ");
  16.                    matriz[f][c] = int.Parse(Console.ReadLine());
  17.                    suma = suma + matriz[f][c];
  18.                }
  19.            }
  20.            String martriz = "";
  21.            for (int f = 0; f < matriz.Length; f++)
  22.            {
  23.                for (int c = 0; c < matriz[f].Length; c++)
  24.                {
  25.                    martriz = martriz + matriz[f][c];
  26.                }
  27.                martriz = martriz + "\n";
  28.            }
  29.  
  30.            Console.Write(martriz);
  31.  
  32.            Console.Write("LA SUMA DE LA MATRIZ ES = " + suma);


Mod: Los códigos deben ir en etiquetas GeSHi, los temas va a su respectivo subforo, el titulo debe ser descriptivo
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines