Advertisement
Zennoma

laba14

Feb 27th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. // laba14.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
  2. //
  3.  
  4. #include <iostream>
  5. #include <stdio.h>
  6. #include <time.h>
  7. #include <conio.h>
  8. #include <string.h>
  9. using namespace std;
  10. void functionmass(int** matrix,int Rows, int Collums )
  11. {
  12.  
  13. int count = 0;
  14. for (int j = 0; j < Rows; j++)
  15. {
  16. for (int i = 0; i < Collums; i++)
  17. {
  18. if (matrix[j][i] % 5 == 0)
  19. {
  20. count++;
  21. }
  22. }
  23. matrix[j][j] = count;
  24. count = 0;
  25. }
  26. }
  27. void function(int** matrix,int Collums, int num)
  28. {
  29. num -= 1;
  30. int count = 0;
  31. for (int i=0; i< Collums; i++)
  32. {
  33. if (matrix[num][i] % 5 == 0)
  34. {
  35. count++;
  36. }
  37. }
  38. matrix[num][num] = count;
  39. }
  40. void printmatrix(int** matrix, int Rows, int Collums)
  41. {
  42. for (int i = 0; i < Rows; i++)
  43. {
  44. for (int j = 0; j < Collums; j++)
  45. {
  46. cout.width(10);
  47. cout << *(*(matrix + i) + j);
  48. }
  49. cout << endl;
  50. }
  51. }
  52. void generation(int** matrix, int Rows, int Collums)
  53. {
  54.  
  55. for (int i = 0; i < Rows; i++)
  56. {
  57. for (int j = 0; j < Collums; j++)
  58. {
  59. cout.width(10);
  60. *(*(matrix + i) + j) = rand() % 21 - 10;
  61. }
  62. }
  63.  
  64. }
  65. void deletematrix(int** matrix, int Rows, int Collums)
  66. {
  67. for (int i = 0; i < Rows; i++)
  68. delete[] matrix[i];
  69. delete[]matrix;
  70. }
  71. int main()
  72. {
  73.  
  74. srand(time(NULL));
  75. int Rows, Collums;
  76. cout << "Enter number of rows" << endl;
  77. cin >> Rows;
  78. cout << "Enter number of collums" << endl;
  79. cin >> Collums;
  80. int** matrix= new int*[Rows]; //массив указателей
  81. for (int i = 0; i < Rows; i++)
  82. {
  83. matrix[i] = new int[Collums]; // Создаем элементы
  84. }
  85. generation(matrix, Rows, Collums);
  86. printmatrix(matrix, Rows, Collums);
  87. int num=0;
  88.  
  89. cout << "choose row or tap 0 for massfunction" << endl;
  90. scanf_s("%d", &num);
  91. if (num!=0)
  92. {
  93. function(matrix, Collums, num);
  94. cout << "New matrix" << endl;
  95. printmatrix(matrix, Rows, Collums);
  96. }
  97. else
  98. {
  99. cout << "function to all rows" << endl;
  100. functionmass(matrix, Rows,Collums);
  101. printmatrix(matrix, Rows, Collums);
  102. }
  103. cout << "matrix deleted" << endl;
  104. deletematrix(matrix, Rows, Collums);
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement