Advertisement
Duffy64

Matriz c#

Feb 21st, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 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 Matrixd
  8. {
  9. class Matrix
  10. {
  11. private int[,] mat; // creacion de matriz
  12.  
  13. public void Cargar()
  14. {
  15. Console.Write("Ingrese la cantidad de filas de la matriz:");
  16. string linea; //guardado de valor
  17. linea = Console.ReadLine();//lector
  18. int filas = int.Parse(linea);
  19.  
  20.  
  21. Console.Write("Ingrese la cantidad de columnas de la matriz:");
  22. linea = Console.ReadLine();
  23. int columnas = int.Parse(linea);
  24. mat = new int[filas, columnas];
  25. //estructura repetitiva se acotan preguntando a la misma matriz la cantidad de filas y la cantidad de columnas para el valor
  26. for (int f = 0; f < mat.GetLength(0); f++)
  27. {
  28. for (int c = 0; c < mat.GetLength(1); c++)
  29. {
  30. Console.Write("Ingrese el valor:");// ingresa el valor
  31. linea = Console.ReadLine();
  32. mat[f, c] = int.Parse(linea);
  33. }
  34. }
  35. }
  36.  
  37.  
  38. //Impresion de la matriz
  39. public void Imprimir()
  40. {
  41. for (int f = 0; f < mat.GetLength(0); f++)
  42. {
  43. for (int c = 0; c < mat.GetLength(1); c++)
  44. {
  45. Console.Write(mat[f, c] + " ");
  46. }
  47. Console.WriteLine();
  48. }
  49. }
  50.  
  51.  
  52.  
  53. static void Main(string[] args)
  54. {
  55. Matrix ma = new Matrix();
  56. ma.Cargar();
  57. ma.Imprimir();
  58. Console.ReadKey();
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement