Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author: Филипповых Матвей
- Group: СБС-901
- вариант: 4.2
- Description: Каждая строка в двумерной матрице представляет собой двоичное число(элементы строки могут ринимать только два значения - нуль или единица).
- Найти номера строк, модуль разности чисел которых - максимален.
- */
- #include <cstdio>
- #include <clocale>
- #include <cstdlib>
- #include <ctime>
- #include <locale>
- #include<iomanip>
- int random(const int a, const int b)
- {
- int rnd = int(rand()) / RAND_MAX;
- return (a + (b - a) * rnd);
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- const size_t MAX_SIZE = 100;
- int A[MAX_SIZE][MAX_SIZE];
- int lines;
- int column;
- int answer = 0;
- int counter;
- srand(time(NULL));
- printf("Введите количесвто строк \n");
- scanf_s("%d", &lines);
- while (lines < 0 || lines>MAX_SIZE)
- {
- printf("нельзя вводить отрицательные числа и числа больше 1000 строк\n");
- printf("Введите количествово строк");
- scanf_s("%d", &lines);
- }
- printf("Введите количесвто столбцов \n");
- scanf_s("%d", &column);
- while (column < 0 || column>MAX_SIZE)
- {
- printf("нельзя вводить отрицательные числа и числа больше 1000 для столбцов\n");
- printf("Введите количествово столбцов");
- scanf_s("%d", &column);
- }
- printf("хотите сами ввести числа в матрицу? если да напишите\"1\" иначе любую другую цифру");
- scanf_s("%d", &answer);
- if (answer == 1)
- {
- for (int i = 0; i < lines; i++)
- {
- for (int j = 0; j < column; j++)
- {
- printf("\nA[%d][%d]=", i + 1, j + 1);
- scanf_s("%d", &A[i + 1][j + 1]);
- }
- }
- }
- else
- {
- for (int i = 0; i < lines; i++)
- {
- for (int j = 0; j < column; j++)
- {
- printf("\nA[%d][%d]=", i + 1, j + 1);
- A[i + 1][j + 1] = random(0, 2);
- printf("%d", A[i + 1][j + 1]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement