Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace igor
- {
- class Matrix
- {
- private int[,] IntArray;
- private int n;
- public Matrix (int aN)
- {
- n = aN;
- IntArray = new int[n, n];
- }
- public void Input ()
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- Console.Write("[{0},{1}] = ", i, j);
- IntArray[i, j] = int.Parse(Console.ReadLine());
- }
- }
- }
- public void Print()
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- Console.Write(IntArray[i, j]);
- }
- Console.WriteLine();
- }
- }
- public int ColSum(int col)
- {
- int sum = 0;
- for (int i = 0; i < n; i++)
- {
- sum += IntArray[i, col];
- }
- return sum;
- }
- public int NullCount
- {
- get {
- int count = 0;
- for (int i = 0; i < n; i++)
- for (int j = 0; j < n; j++)
- if(IntArray[i, j] == 0) count++;
- return count;
- }
- }
- public int MainDiagonal
- {
- set {
- for (int i = 0; i < n; i++)
- IntArray[i, i] = value;
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Matrix matrix = new Matrix(3);
- matrix.Input();
- Console.WriteLine("set main diagonal to 9");
- matrix.MainDiagonal = 9;
- matrix.Print();
- Console.WriteLine("sum of 0 col = {0}", matrix.ColSum(0));
- Console.WriteLine("count of Null els = {0}", matrix.NullCount);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement