Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "Russian");
- cout « "Никульченков М.Е. УМЛ-111\n";
- cout « "Матрица вводится путем рандомного подсталения чисел\n";
- const int n = 5;
- int old_data[n][n]; // изначальный массив
- int new_data[n]; // новый массив
- srand(time(NULL));
- for (int x = 0; x < n; x++)
- {
- for (int y = 0; y < n; y++)
- {
- old_data[x][y] = rand() % 21 * pow(-1.0, rand() % 2);
- cout « old_data[x][y] « ' ';
- }
- cout « endl;
- }
- cout « endl;
- int z[n];
- int c = 0;
- for (int x = 0; x < n; x++)//первый отрицательный элемент
- {
- for (int y = 0; y < n; y++)
- {
- if (old_data[x][y] < 0)
- {
- z[x] = c + 1;
- y = -1;
- x++;
- if (x >= n) break;
- }
- }
- }
- cout « "Первые отрицательные элементы из каждой строки: \n";
- for (int x = 0; x < n; x++)// печатаем что получилось после работы программы
- {
- cout « z[x] « ' ';
- }
- cout « endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment