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 basics
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = Int32.Parse(Console.ReadLine());
- int[,] matrix = new int[n, n];
- int j = 0, i;
- for (i = 0; i < n; i++)
- {
- for (j = 0; j < n; j++)
- {
- matrix[i, j] = 0;
- Console.Write("{0}\t", matrix[i, j]);
- }
- Console.WriteLine();
- }
- Console.WriteLine("Куда поставить число 1?");
- int a = Int32.Parse(Console.ReadLine());
- int b = Int32.Parse(Console.ReadLine());
- matrix[a, b] = 1;
- DrawMass(n, matrix);
- int countRow = 0;
- foreach (var x in SummRows(n, matrix))
- Console.WriteLine("Summ of row number [{0}] : {1}", ++countRow, x);
- int countCol = 0;
- foreach (var x in SummCols(n, matrix))
- Console.WriteLine("Summ of col number [{0}] : {1}", ++countCol, x);
- int ansv = SummDiag(n, matrix);
- Console.WriteLine(ansv);
- }
- public static int SummDiag(int n, int[,] arr)
- {
- int count = 0;
- for (var i = 1; i < n; ++i)
- {
- if (arr[i, i] == 1)
- {
- count++;
- }
- }
- return count;
- }
- public static IEnumerable<int> SummCols(int n, int[,] arr)
- {
- int ret_sum;
- for (int j = 0; j < n; ++j)
- {
- ret_sum = 0;
- for (int i = 0; i < n; ++i)
- ret_sum += arr[i, j];
- yield return ret_sum;
- }
- }
- public static IEnumerable<int> SummRows(int n, int[,] arr)
- {
- int ret_sum;
- for (int i = 0; i < n; ++i)
- {
- ret_sum = 0;
- for (int j = 0; j < n; ++j)
- ret_sum += arr[i, j];
- yield return ret_sum;
- }
- }
- static void DrawMass(int n, int[,] matrix)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- Console.Write("{0}\t", matrix[i, j]);
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment