Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Matriz
  8. {
  9. class Matriz
  10. {
  11. private int[,] mat;
  12.  
  13. public void Cargar()
  14. {
  15. Console.Write("Cuántas filas tiene la matriz?");
  16. string linea;
  17. linea = Console.ReadLine();
  18. int filas = int.Parse(linea);
  19. Console.Write("Cuántas columnas tiene la matriz?");
  20. linea = Console.ReadLine();
  21. int columnas = int.Parse(linea);
  22. mat = new int[filas, columnas];
  23. for (int f = 0; f < mat.GetLength(0); f++)
  24. {
  25. for (int c = 0; c < mat.GetLength(1); c++)
  26. {
  27. Console.Write("Introduzca posición [" + (f + 1) + "," + (c + 1) + "]: ");
  28. string linea2;
  29. linea2 = Console.ReadLine();
  30. mat[f, c] = int.Parse(linea2);
  31. }
  32. }
  33. }
  34.  
  35. public void Imprimir()
  36. {
  37. for (int f = 0; f < mat.GetLength(0); f++)
  38. {
  39. for (int c = 0; c < mat.GetLength(1); c++)
  40. {
  41. Console.Write(mat[f, c] + " ");
  42. }
  43. Console.WriteLine();
  44. }
  45. }
  46.  
  47. static void Main(string[] args)
  48. {
  49. Matriz ma = new Matriz();
  50. ma.Cargar();
  51. ma.Imprimir();
  52.  
  53. Console.ReadKey();
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement