Advertisement
mlmisha

Matrix

Apr 25th, 2020
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1. using System;
  2. namespace text
  3. {
  4.    
  5.     class MainClass
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             Console.WriteLine("Количество столбцов");
  10.             int n = int.Parse(Console.ReadLine());
  11.             Console.WriteLine("Количество строк");
  12.             int m = int.Parse(Console.ReadLine());
  13.             double [,] A = new double[n, m];
  14.             for (int i = 0; i < m; i++)
  15.             {
  16.                 Random rnd = new Random();
  17.                 for (int t = 0; t < n; t++)
  18.                 {
  19.                     A[t, i] = rnd.Next(-50,50);
  20.                 }
  21.             }
  22.             Console.WriteLine("Изначальная матрица");
  23.             for (int i = 0; i<m; i++)
  24.             {
  25.                 for (int t = 0; t<n; t++)
  26.                 {
  27.                     Console.Write("{0} ", A[t, i]);
  28.                 }
  29.                 Console.WriteLine();
  30.             }
  31.             int l = -1;
  32.             double s = 0;
  33.             int u = 0;
  34.             for (int i = 0; i<m; i++)
  35.             {
  36.                 s = 0;
  37.                 u = 0;
  38.                 double j = A[0, i];
  39.                 int r = 0;
  40.                 double k = j;
  41.                 int y = r;
  42.                 if (A[0,i] < 0)
  43.                 {
  44.                     l = 0;
  45.                     u++;
  46.                 }
  47.                 for (int t = 1; t<n; t++)
  48.                 {
  49.                     if (A[t, i]>j)
  50.                     {
  51.                         j = A[t,i];
  52.                         r = t;
  53.                     }
  54.                     if (A[t, i]<k)
  55.                     {
  56.                         k = A[t,i];
  57.                         y = t;
  58.                     }
  59.                     if (A[t, i] < 0)
  60.                     {
  61.                         l = t;
  62.                         s += A[t,i];
  63.                         u++;
  64.                     }
  65.                 }
  66.                 if (r > l)
  67.                 {
  68.                     if (s != 0)
  69.                     {
  70.                         s /= u;
  71.                         Math.Round(s, 2);
  72.                     }
  73.                     A[r, i] = s;
  74.                 }
  75.                 else
  76.                 {
  77.                     A[r, i] *= 2;
  78.                 }
  79.             }
  80.             Console.WriteLine("Итоговая матрица");
  81.             for (int i = 0; i < m; i++)
  82.             {
  83.                 for (int t = 0; t < n; t++)
  84.                 {
  85.                     Console.Write("{0} ", A[t, i]);
  86.                 }
  87.                 Console.WriteLine();
  88.             }
  89.         }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement