Advertisement
Guest User

Matriz2D

a guest
Sep 18th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Matriz2D
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Console.WriteLine("Ingrese la cantidad de columnas:");
  10.             int col = int.Parse(Console.ReadLine());
  11.             Console.WriteLine("Ingrese la cantidad de filas:");
  12.             int fil = int.Parse(Console.ReadLine());
  13.             int[,] matriz = new int[col, fil];
  14.             int num = 0;
  15.             int poscol = 0;
  16.             int posfil = 0;
  17.             Console.WriteLine("Ahora ingresa los números en cada fila de cada columna");
  18.             for(int i = 0; i < col; i++)
  19.             {
  20.                 for(int j = 0; j < fil; j++)
  21.                 {
  22.                     Console.WriteLine("Ingrese el número para la columna {0} y fila {1}", i, j);
  23.                     int snum = int.Parse(Console.ReadLine());
  24.                     matriz[i, j] = snum;
  25.                 }
  26.             }
  27.             //se recorre la matriz para buscar el número más grande
  28.             for(int i = 0; i < col; i++)
  29.             {
  30.                 for(int j = 0; j < fil; j++)
  31.                 {
  32.                     if(i == 0)
  33.                     {
  34.                         num = matriz[i, j];
  35.                         poscol = i;
  36.                         posfil = j;
  37.                     }
  38.                     else
  39.                     {
  40.                         if(matriz[i, j] > num)
  41.                         {
  42.                             num = matriz[i, j];
  43.                             poscol = i;
  44.                             posfil = j;
  45.                         }
  46.                     }
  47.                 }
  48.             }
  49.  
  50.             Console.WriteLine("El número más grande es: {0} se encuentra en la columna {1} y en la fila {2}", num, poscol, posfil);
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement