VitalyD

Untitled

May 8th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.10 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(matrix.
  28.  
  29.             bool ok = false;
  30.  
  31.             while (ok == false)
  32.             {
  33.                 Console.WriteLine("Куда поставить число 1?");
  34.                 int a = Int32.Parse(Console.ReadLine());
  35.                 int b = Int32.Parse(Console.ReadLine());
  36.                 matrix[a, b] = 1;
  37.                 DrawMass(n, matrix);
  38.                 int count = 0;
  39.                 foreach (var x in SummRows(n, matrix))
  40.                 {
  41.                     Console.WriteLine("Summ of row number [{0}] : {1}", ++count, x);
  42.                     if (x == n)
  43.                     {
  44.                           ok = true;
  45.                     }    
  46.                 }
  47.                 Console.WriteLine("Программа завершена.");
  48.             }  
  49.         }
  50.  
  51.  
  52.         public static IEnumerable<int> SummRows(int n, int[,] arr)
  53.         {
  54.             int ret_sum;
  55.             for (int i = 0; i < n; ++i)
  56.             {
  57.                 ret_sum = 0;
  58.                 for (int j = 0; j < n; ++j)
  59.                     ret_sum += arr[i, j];
  60.  
  61.                 yield return ret_sum;
  62.  
  63.             }
  64.         }
  65.  
  66.         static void DrawMass(int n, int[,] matrix)
  67.         {
  68.             for (int i = 0; i < n; i++)
  69.             {
  70.                 for (int j = 0; j < n; j++)
  71.                 {
  72.                     Console.Write("{0}\t", matrix[i, j]);
  73.                 }
  74.                 Console.WriteLine();
  75.             }
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment