Advertisement
fferum

Untitled

Apr 23rd, 2020
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.20 KB | None | 0 0
  1. /*
  2. Author: Филипповых Матвей
  3. Group: СБС-901
  4. вариант: 4.2
  5. Description: Каждая строка в двумерной матрице представляет собой двоичное число(элементы строки могут ринимать только два значения - нуль или единица).
  6. Найти номера строк, модуль разности чисел которых - максимален.
  7. */
  8. #include <cstdio>
  9. #include <clocale>
  10. #include <cstdlib>
  11. #include <ctime>
  12. #include <locale>
  13. #include<iomanip>
  14. int random(const int a, const int b)
  15. {
  16.     int rnd = int(rand()) / RAND_MAX;
  17.     return (a + (b - a) * rnd);
  18. }
  19. int main()
  20. {
  21.     setlocale(LC_ALL, "Russian");
  22.     const size_t MAX_SIZE = 100;
  23.     int A[MAX_SIZE][MAX_SIZE];
  24.     int lines;
  25.     int column;
  26.     int answer = 0;
  27.     int counter;
  28.     srand(time(NULL));
  29.  
  30.  
  31.     printf("Введите количесвто строк \n");
  32.     scanf_s("%d", &lines);
  33.     while (lines < 0 || lines>MAX_SIZE)
  34.     {
  35.         printf("нельзя вводить отрицательные числа и числа больше 1000 строк\n");
  36.         printf("Введите количествово строк");
  37.         scanf_s("%d", &lines);
  38.     }
  39.  
  40.     printf("Введите количесвто столбцов \n");
  41.     scanf_s("%d", &column);
  42.     while (column < 0 || column>MAX_SIZE)
  43.     {
  44.         printf("нельзя вводить отрицательные числа и числа больше 1000 для столбцов\n");
  45.         printf("Введите количествово столбцов");
  46.         scanf_s("%d", &column);
  47.     }
  48.  
  49.  
  50.  
  51.  
  52.  
  53.     printf("хотите сами ввести числа в матрицу? если да напишите\"1\" иначе любую другую цифру");
  54.     scanf_s("%d", &answer);
  55.     if (answer == 1)
  56.     {
  57.         for (int i = 0; i < lines; i++)
  58.         {
  59.             for (int j = 0; j < column; j++)
  60.             {
  61.                 printf("\nA[%d][%d]=", i + 1, j + 1);
  62.                 scanf_s("%d", &A[i + 1][j + 1]);
  63.             }
  64.         }
  65.     }
  66.     else
  67.     {
  68.         for (int i = 0; i < lines; i++)
  69.         {
  70.             for (int j = 0; j < column; j++)
  71.             {
  72.                 printf("\nA[%d][%d]=", i + 1, j + 1);
  73.                 A[i + 1][j + 1] = random(0, 2);
  74.                 printf("%d", A[i + 1][j + 1]);
  75.  
  76.             }
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement