Advertisement
Zennoma

Domzad

Feb 27th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include <conio.h>
  4. using namespace std;
  5.  
  6. void printmatrix(int** matrix, int Rows, int Collums)
  7. {
  8. for (int i = 0; i < Rows; i++)
  9. {
  10. for (int j = 0; j < Collums; j++)
  11. {
  12. cout.width(10);
  13. cout << *(*(matrix + i) + j);
  14. }
  15. cout << endl;
  16. }
  17. }
  18. void generation(int** matrix, int Rows, int Collums)
  19. {
  20.  
  21. for (int i = 0; i < Rows; i++)
  22. {
  23. for (int j = 0; j < Collums; j++)
  24. {
  25. cout.width(10);
  26. *(*(matrix + i) + j) = rand() % 21 - 10;
  27. }
  28. }
  29.  
  30. }
  31. void deletematrix(int** matrix, int Rows, int Collums)
  32. {
  33. for (int i = 0; i < Rows; i++)
  34. delete[] matrix[i];
  35. delete[]matrix;
  36. }
  37.  
  38. void prog(int** matrix, int Rows, int Collums)
  39. {
  40. int temp1,temp2;
  41. int count = 0;
  42. int t = Rows -1 ;
  43. for (int j = 0; j < Collums; j++)
  44. {
  45. for (int i = 0; i < Rows; i++)
  46. {
  47. if (matrix[i][j] %3==0)
  48. count++;//подсчет числа кратным 3
  49. }
  50. temp1 = matrix[t][j];
  51. for (int k = t; k < Rows; k++)
  52. {
  53. temp2 = matrix[k + 1][j];
  54. matrix[k + 1][j] = temp1;
  55. temp1 = temp2;
  56. }
  57. matrix[t][j] = count;
  58. t--;
  59. count = 0;
  60. }
  61. }
  62.  
  63.  
  64. int main()
  65. {
  66. srand(time(NULL));
  67. int Rows, Collums;
  68. cout << "Enter number of rows" << endl;
  69. cin >> Rows;
  70. cout << "Enter number of collums" << endl;
  71. cin >> Collums;
  72. int** matrix = new int* [Rows+1]; //массив указателей
  73. for (int i = 0; i < Rows+1; i++)
  74. {
  75. matrix[i] = new int[Collums]; // Создаем элементы
  76. }
  77. generation(matrix, Rows, Collums);
  78. printmatrix(matrix, Rows, Collums);
  79. prog(matrix, Rows, Collums);
  80. cout << "New matrix. On optional diagonal elements multiple 3"<< endl;
  81.  
  82.  
  83. for (int i = 0; i < Rows+1; i++)
  84. {
  85. for (int j = 0; j < Collums; j++)
  86. {
  87. cout.width(10);
  88. cout << *(*(matrix + i) + j);
  89. }
  90. cout << endl;
  91. }
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement