VitalyD

Untitled

May 8th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.69 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 basics
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = Int32.Parse(Console.ReadLine());
  14.             int[,] matrix = new int[n, n];
  15.             int j = 0, i;
  16.  
  17.             for (i = 0; i < n; i++)
  18.             {
  19.                 for (j = 0; j < n; j++)
  20.                 {
  21.                     matrix[i, j] = 0;
  22.                     Console.Write("{0}\t", matrix[i, j]);
  23.                 }
  24.                 Console.WriteLine();
  25.             }
  26.  
  27.                 Console.WriteLine("Куда поставить число 1?");
  28.                 int a = Int32.Parse(Console.ReadLine());
  29.                 int b = Int32.Parse(Console.ReadLine());
  30.                 matrix[a, b] = 1;
  31.                 DrawMass(n, matrix);
  32.  
  33.  
  34.  
  35.                 int countRow = 0;
  36.                 foreach (var x in SummRows(n, matrix))
  37.                     Console.WriteLine("Summ of row number [{0}] : {1}", ++countRow, x);
  38.  
  39.                 int countCol = 0;
  40.                 foreach (var x in SummCols(n, matrix))
  41.                     Console.WriteLine("Summ of col number [{0}] : {1}", ++countCol, x);
  42.  
  43.                  int ansv = SummDiag(n, matrix);
  44.                  Console.WriteLine(ansv);
  45.  
  46.  
  47.  
  48.  
  49.         }
  50.  
  51.         public static int SummDiag(int n, int[,] arr)
  52.         {
  53.             int count = 0;
  54.             for (var i = 1; i < n; ++i)
  55.             {
  56.                 if (arr[i, i] == 1)
  57.                 {
  58.                     count++;
  59.                 }
  60.             }
  61.                
  62.  
  63.             return count;
  64.         }
  65.  
  66.         public static IEnumerable<int> SummCols(int n, int[,] arr)
  67.         {
  68.             int ret_sum;
  69.             for (int j = 0; j < n; ++j)
  70.             {
  71.                 ret_sum = 0;
  72.                 for (int i = 0; i < n; ++i)
  73.                     ret_sum += arr[i, j];
  74.  
  75.                 yield return ret_sum;
  76.  
  77.             }
  78.         }
  79.  
  80.         public static IEnumerable<int> SummRows(int n, int[,] arr)
  81.         {
  82.             int ret_sum;
  83.             for (int i = 0; i < n; ++i)
  84.             {
  85.                 ret_sum = 0;
  86.                 for (int j = 0; j < n; ++j)
  87.                     ret_sum += arr[i, j];
  88.  
  89.                 yield return ret_sum;
  90.  
  91.             }
  92.         }
  93.  
  94.         static void DrawMass(int n, int[,] matrix)
  95.         {
  96.             for (int i = 0; i < n; i++)
  97.             {
  98.                 for (int j = 0; j < n; j++)
  99.                 {
  100.                     Console.Write("{0}\t", matrix[i, j]);
  101.                 }
  102.                 Console.WriteLine();
  103.             }
  104.         }
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment