Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Samost_Kudrya_23_11
  4. {
  5. /*
  6. Вариант 8
  7. Кудря Иван БПИ173
  8. */
  9.  
  10. class MatrixE
  11. {
  12. private int _length = 10;
  13. private int [,] _mtr;
  14. public int [,] mtr
  15. {
  16. get { return _mtr; }
  17. }
  18. public int length
  19. {
  20. get { return _length; }
  21. }
  22. public int this[int i,int j]
  23. {
  24. get
  25. {
  26. if (i<_length&&i>=0&&j>=0&&j<_length)
  27. {
  28. return _mtr[i, j];
  29. }
  30. else
  31. {
  32. return -1;
  33. }
  34. }
  35. }
  36. public MatrixE()
  37. {
  38. _mtr = new int[_length, _length];
  39. MatrixCre();
  40. }
  41. private void MatrixCre()
  42. {
  43. for (int i = 0; i < _length;i++)
  44. {
  45. for (int j = 0; j < _length;j++)
  46. {
  47. if (j+1==_length-i) {
  48. _mtr[i, j] = 0;
  49. }
  50. else
  51. {
  52. _mtr[i, j] = 1;
  53. }
  54. }
  55. }
  56. }
  57.  
  58. }
  59. class MainClass
  60. {
  61. public static void Main(string[] args)
  62. {
  63. MatrixE example = new MatrixE();
  64. do
  65. {
  66. Console.Clear();
  67. for (int q = 0;q< example.length; q++)
  68. {
  69. GetView(example, q);
  70. }
  71. int i = 0;
  72. int j = 0;
  73. do
  74. {
  75. i = InputRowandColumn("i");
  76. j = InputRowandColumn("j");
  77. if (example[i, j] != -1)
  78. {
  79. Console.WriteLine("Элемент i строки, j столбца {0}", example[i, j]);
  80. }
  81. else
  82. {
  83. Console.WriteLine("Ошибка границ,элемент i строки, j столбца {0}", example[i, j]);
  84. }
  85. } while (j != -1 || i != -1);
  86. Console.WriteLine("Чтобы выйти из программы нажмие Esc. Продолжить любую другую клавишу");
  87. } while (Console.ReadKey().Key != ConsoleKey.Escape);
  88. }
  89. public static int InputRowandColumn(string inp)
  90. {
  91. int i = 0;
  92. string input = "";
  93. do
  94. {
  95. Console.WriteLine("Введите "+inp);
  96. input = Console.ReadLine();
  97. } while (!int.TryParse(input, out i));
  98. return (i);
  99. }
  100. public static void GetView(MatrixE exp,int j)
  101. {
  102. string output="";
  103. for (int i = 0; i < exp.length; i++)
  104. {
  105. output += exp[i, j] + " ";
  106. }
  107. Console.WriteLine(output+":");
  108.  
  109. }
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement