Advertisement
gasaichan

CLR_shenanigans

Oct 20th, 2018
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. #include "stdafx.h"
  2.  
  3. using namespace System;
  4.  
  5. void matrix_to_string(array<int, 2>^ arr) {
  6.     for (int i = 0; i < arr->GetLength(0); i++) {
  7.         for (int j = 0; j < arr->GetLength(1); j++) {
  8.             Console::Write(arr[i, j] + "\t");
  9.         }
  10.         Console::WriteLine();
  11.     }
  12. }
  13.  
  14. void array_to_string(array<int>^ arr) {
  15.     for (int i = 0; i < arr->GetLength(0); i++) {
  16.         Console::Write(arr[i] + "\t");
  17.     }
  18.     Console::WriteLine();
  19. }
  20.  
  21.  
  22.  
  23. int main(array<System::String ^> ^args)
  24. {
  25.     const int ROWS = 5;
  26.     const int COLS = 7;
  27.  
  28.     Random^ r = gcnew Random;
  29.  
  30.     array<int, 2>^ M = gcnew array<int, 2>(ROWS, COLS);
  31.     array<int, 2>^ N = gcnew array<int, 2>(ROWS, COLS);
  32.  
  33.     for (int i = 0; i < ROWS; i++) {
  34.         for (int j = 0; j < COLS; j++) {
  35.             M[i, j] = r->Next(-100, 100);
  36.             N[i, j] = r->Next(-100, 100);
  37.         }
  38.     }
  39.  
  40.     Console::WriteLine("Массив M:");
  41.     matrix_to_string(M);
  42.  
  43.     Console::WriteLine("Массив N:");
  44.     matrix_to_string(N);
  45.  
  46.     array<int>^ C = gcnew array<int>(ROWS);
  47.     array<int>^ D = gcnew array<int>(ROWS);
  48.  
  49.     int m_counter = 0;
  50.     int n_counter = 0;
  51.  
  52.     for (int i = 0; i < M->GetLength(0); i++) {
  53.         for (int j = 0; j < M->GetLength(1); j++) {
  54.             if (M[i, j] < 0) {
  55.                 m_counter++;
  56.             }
  57.             if (N[i, j] < 0) {
  58.                 n_counter++;
  59.             }
  60.         }
  61.         C[i] = m_counter;
  62.         m_counter = 0;
  63.         D[i] = n_counter;
  64.         n_counter = 0;
  65.     }
  66.  
  67.     Console::WriteLine("Массив C, каждый элемент которого содержит количество отрицательных элементов в соответствующих строках массива M");
  68.     array_to_string(C);
  69.  
  70.     Console::WriteLine("Массив D, каждый элемент которого содержит количество отрицательных элементов в соответствующих строках массива N");
  71.     array_to_string(D);
  72.  
  73.  
  74.     Console::ReadLine();
  75.     return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement