0_liprikon_0

Миша_номера

Jun 20th, 2021
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <ctime>
  4. #include <cstdlib>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. setlocale(LC_ALL, "Russian");
  11. cout « "Никульченков М.Е. УМЛ-111\n";
  12. cout « "Матрица вводится путем рандомного подсталения чисел\n";
  13. const int n = 5;
  14. int old_data[n][n]; // изначальный массив
  15. int new_data[n]; // новый массив
  16. srand(time(NULL));
  17. for (int x = 0; x < n; x++)
  18. {
  19. for (int y = 0; y < n; y++)
  20. {
  21. old_data[x][y] = rand() % 21 * pow(-1.0, rand() % 2);
  22. cout « old_data[x][y] « ' ';
  23. }
  24. cout « endl;
  25. }
  26. cout « endl;
  27.  
  28. int z[n];
  29. int c = 0;    
  30. for (int x = 0; x < n; x++)//первый отрицательный элемент
  31. {
  32. for (int y = 0; y < n; y++)
  33. {
  34. if (old_data[x][y] < 0)
  35. {
  36. z[x] = c + 1;
  37. y = -1;
  38. x++;
  39. if (x >= n) break;
  40. }
  41. }
  42. }
  43. cout « "Первые отрицательные элементы из каждой строки: \n";
  44. for (int x = 0; x < n; x++)// печатаем что получилось после работы программы
  45. {
  46. cout « z[x] « ' ';
  47. }
  48. cout « endl;
  49.  
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment