Advertisement
ostapdontstop

igor

May 14th, 2019
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.11 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 igor
  8. {
  9.     class Matrix
  10.     {
  11.         private int[,] IntArray;
  12.         private int n;
  13.  
  14.         public Matrix (int aN)
  15.         {
  16.             n = aN;
  17.             IntArray = new int[n, n];
  18.         }
  19.         public void Input ()
  20.         {
  21.             for (int i = 0; i < n; i++)
  22.             {
  23.                 for (int j = 0; j < n; j++)
  24.                 {
  25.                     Console.Write("[{0},{1}] = ", i, j);
  26.                     IntArray[i, j] = int.Parse(Console.ReadLine());
  27.                 }
  28.             }
  29.         }
  30.         public void Print()
  31.         {
  32.             for (int i = 0; i < n; i++)
  33.             {
  34.                 for (int j = 0; j < n; j++)
  35.                 {
  36.                     Console.Write(IntArray[i, j]);
  37.                 }
  38.                 Console.WriteLine();
  39.             }
  40.         }
  41.         public int ColSum(int col)
  42.         {
  43.             int sum = 0;
  44.             for (int i = 0; i < n; i++)
  45.             {
  46.                 sum += IntArray[i, col];
  47.             }
  48.             return sum;
  49.         }
  50.         public int NullCount
  51.         {
  52.             get {
  53.                 int count = 0;
  54.  
  55.                 for (int i = 0; i < n; i++)
  56.                     for (int j = 0; j < n; j++)
  57.                         if(IntArray[i, j] == 0) count++;
  58.  
  59.                 return count;
  60.             }
  61.            
  62.         }
  63.         public int MainDiagonal
  64.         {
  65.             set {
  66.                 for (int i = 0; i < n; i++)
  67.                     IntArray[i, i] = value;
  68.             }
  69.            
  70.         }
  71.  
  72.     }
  73.  
  74.     class Program
  75.     {
  76.         static void Main(string[] args)
  77.         {
  78.             Matrix matrix = new Matrix(3);
  79.             matrix.Input();
  80.             Console.WriteLine("set main diagonal to 9");
  81.             matrix.MainDiagonal = 9;
  82.             matrix.Print();
  83.             Console.WriteLine("sum of 0 col = {0}", matrix.ColSum(0));
  84.             Console.WriteLine("count of Null els = {0}", matrix.NullCount);
  85.         }
  86.     }
  87.  
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement