Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Samost_Kudrya_23_11
- {
- /*
- Вариант 8
- Кудря Иван БПИ173
- */
- class MatrixE
- {
- private int _length = 10;
- private int [,] _mtr;
- public int [,] mtr
- {
- get { return _mtr; }
- }
- public int length
- {
- get { return _length; }
- }
- public int this[int i,int j]
- {
- get
- {
- if (i<_length&&i>=0&&j>=0&&j<_length)
- {
- return _mtr[i, j];
- }
- else
- {
- return -1;
- }
- }
- }
- public MatrixE()
- {
- _mtr = new int[_length, _length];
- MatrixCre();
- }
- private void MatrixCre()
- {
- for (int i = 0; i < _length;i++)
- {
- for (int j = 0; j < _length;j++)
- {
- if (j+1==_length-i) {
- _mtr[i, j] = 0;
- }
- else
- {
- _mtr[i, j] = 1;
- }
- }
- }
- }
- }
- class MainClass
- {
- public static void Main(string[] args)
- {
- MatrixE example = new MatrixE();
- do
- {
- Console.Clear();
- for (int q = 0;q< example.length; q++)
- {
- GetView(example, q);
- }
- int i = 0;
- int j = 0;
- do
- {
- i = InputRowandColumn("i");
- j = InputRowandColumn("j");
- if (example[i, j] != -1)
- {
- Console.WriteLine("Элемент i строки, j столбца {0}", example[i, j]);
- }
- else
- {
- Console.WriteLine("Ошибка границ,элемент i строки, j столбца {0}", example[i, j]);
- }
- } while (j != -1 || i != -1);
- Console.WriteLine("Чтобы выйти из программы нажмие Esc. Продолжить любую другую клавишу");
- } while (Console.ReadKey().Key != ConsoleKey.Escape);
- }
- public static int InputRowandColumn(string inp)
- {
- int i = 0;
- string input = "";
- do
- {
- Console.WriteLine("Введите "+inp);
- input = Console.ReadLine();
- } while (!int.TryParse(input, out i));
- return (i);
- }
- public static void GetView(MatrixE exp,int j)
- {
- string output="";
- for (int i = 0; i < exp.length; i++)
- {
- output += exp[i, j] + " ";
- }
- Console.WriteLine(output+":");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement