Advertisement
Schnuk

376b

Jan 16th, 2021
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. namespace ExamTasks
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Random rnd = new Random();
  10.             int m = int.Parse(Console.ReadLine());
  11.             int[] a = new int[m];
  12.             int countNegativeElements = 0;
  13.             Console.WriteLine("Целые числа от a1 до am:");
  14.             for (int i = 0; i < m; i++)
  15.             {
  16.                 a[i] = rnd.Next(-9, 10);
  17.                 if (a[i] >= 0)
  18.                     Console.Write(" ");
  19.                 Console.Write(a[i] +"\t");
  20.             }
  21.             int[,] matrix = new int[m, m];
  22.             Console.WriteLine("\n\nСгенерированная матрица:");
  23.             for (int i = 0; i < m; i++)
  24.             {
  25.                 for (int j = 0; j < m; j++)
  26.                 {
  27.                     matrix[i, j] = rnd.Next(-9, 10);
  28.                     if (matrix[i, j] >= 0)
  29.                         Console.Write(" ");
  30.                     Console.Write(matrix[i, j] + "\t");
  31.                 }
  32.                 Console.Write("\n");
  33.             }
  34.             for (int i = 0; i < m; i++)
  35.             {
  36.                 if (a[i] > 0)
  37.                     for (int j = 0; j < m; j++)
  38.                     {
  39.                         if (matrix[i, j] < 0)
  40.                             countNegativeElements++;
  41.                     }
  42.                 Console.WriteLine(countNegativeElements);
  43.                 countNegativeElements = 0;
  44.             }
  45.         }
  46.     }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement