Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.34 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 lab_13_ex_3
  8. {
  9.     class Program
  10.     {
  11.         static void fill(int[,] a)
  12.         {
  13.             Random R = new Random();
  14.             for (int i = 0; i < a.GetLength(0); i++)
  15.             {
  16.                 for (int j = 0; j < a.GetLength(1); j++)
  17.                 {
  18.                     a[i, j] = R.Next(1);
  19.                 }
  20.             }
  21.  
  22.         }
  23.         static void output(int[,] a)
  24.         {
  25.             Console.WriteLine("____________________________________________");
  26.             for (int i = 0; i < a.GetLength(0); i++)
  27.             {
  28.                 for (int j = 0; j < a.GetLength(1); j++)
  29.                 {
  30.                     Console.Write(a[i, j] + " ");
  31.                 }
  32.                 Console.WriteLine("");
  33.             }
  34.             Console.WriteLine("____________________________________________");
  35.         }
  36.         static void output(int [] a)
  37.         {
  38.             Console.WriteLine("____________________________________________");
  39.             for (int i = 0; i < a.Length; i++)
  40.             {
  41.                 Console.Write(a[i] + " ");
  42.             }
  43.             Console.WriteLine("");
  44.             Console.WriteLine("____________________________________________");
  45.         }
  46.         static void form1(int N, int[,] a, int[] b)
  47.         {
  48.             int count = 0;
  49.             int count1 = 0;
  50.             for (int i = 0; i < a.GetLength(1); i++)
  51.             {
  52.                 for (int j = 0; j < a.GetLength(0); j++)
  53.                 {
  54.                     if (a[j,i] > N)
  55.                     {
  56.                         count++;
  57.                     }
  58.                     if(j == a.GetLength(0) - 1)
  59.                     {
  60.                         b[count1] = count;
  61.                         count = 0;
  62.                         count1++;
  63.                     }
  64.                 }
  65.             }
  66.         }
  67.         static void form2(int N, int[,] a, int[] b)
  68.         {
  69.             int sum = 0;
  70.             int count1 = 0;
  71.             for (int i = 0; i < a.GetLength(0); i++)
  72.             {
  73.                 for (int j = 0; j < a.GetLength(1); j++)
  74.                 {
  75.                     if(a[i,j] < N)
  76.                     {
  77.                         sum += a[i, j];
  78.                     }
  79.                     if (j == a.GetLength(0) - 1)
  80.                     {
  81.                         b[count1] = sum;
  82.                         sum = 0;
  83.                         count1++;
  84.                     }
  85.                 }
  86.             }
  87.         }
  88.         static void form3(int [,] a, int [] b)
  89.         {
  90.             int count = 0;
  91.             bool f1 = true;
  92.             int c;
  93.             for (int i = 0; i < a.GetLength(0); i++)
  94.             {
  95.                 f1 = true;
  96.                 c = a[i, 0];
  97.                 for (int j = 0; j < a.GetLength(1); j++)
  98.                 {
  99.                     if (c != a[i, j])
  100.                     {
  101.                         f1 = false;
  102.                     }
  103.                     if (j == a.GetLength(1) - 1 && f1)
  104.                     {
  105.                         b[count] = i + 1;
  106.                         count++;
  107.                     }
  108.                 }
  109.             }
  110.         }
  111.         static int form3_count(int[,] a)
  112.         {
  113.             int count = 0;
  114.             bool f1 = true;
  115.             int c;
  116.             for (int i = 0; i < a.GetLength(0); i++)
  117.             {
  118.                 f1 = true;
  119.                 c = a[i, 0];
  120.                 for (int j = 0; j < a.GetLength(1); j++)
  121.                 {
  122.                     if(c != a[i, j])
  123.                     {
  124.                         f1 = false;
  125.                     }
  126.                     if(j == a.GetLength(1) - 1 && f1)
  127.                     {
  128.                         count++;
  129.                     }
  130.                 }
  131.             }
  132.             return count;
  133.         }
  134.         static void Main(string[] args)
  135.         {
  136.             int N = 5;
  137.             int[] b = new int[N];
  138.             int[] c = new int[5];
  139.             int[,] a = new int[N,N];
  140.             int[] d = new int[form3_count(a)];
  141.             fill(a);
  142.             output(a);
  143.             form1(65, a, b);
  144.             output(b);
  145.             form2(65, a, c);
  146.             output(c);
  147.             form3(a, d);
  148.             output(d);
  149.  
  150.         }
  151.     }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement