ChameL1oN

Лаба5_Задача3(Вар.13)

Dec 17th, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <locale>
  4. #include <time.h>
  5. #include <iomanip>
  6.  
  7.  
  8. using namespace std;
  9.  
  10.  
  11.  
  12.  
  13. void Print_Matr(int** matr, int n, int m){ //Функция для печати матрицы
  14. int i = 0, j = 0;
  15. while (j < m){
  16. while (i < n){
  17. cout << setw(6) << matr[i][j] << " ";
  18. i++;
  19. }
  20. i = 0;
  21. cout << endl;
  22. j++;
  23. }
  24. }
  25.  
  26. int* form_mas(int count){
  27. int* massive = new int[count];
  28. int a = 0;
  29.  
  30. while (a < count){
  31. massive[a] = rand() % 50;
  32. a++;
  33. }
  34. return massive;
  35. }
  36.  
  37. int** form_matr(int n, int m)
  38. {
  39. int **matr = new int*[n]; //выделение памяти под массив указателей
  40. for (int i = 0; i < n; i++){
  41.  
  42. matr[i] = form_mas(m);
  43. }
  44. return matr;//возвращаем указатель на массив указателей
  45. }
  46.  
  47. void delete_str(int** matr, int n, int m){
  48. // Удалить строки, в которых есть простые числа
  49. int a = 0, i=0, j = 0,prost=0,b;
  50. int k = 0;
  51. while (j < m){
  52. while (i < n){
  53. for (k = 2; (k < (matr[i][j]-1)) && (prost==0); k++){
  54. if (matr[i][j] % k == 0 ){
  55. prost = 1;
  56. }
  57. }
  58. if (prost == 0 && (abs(matr[i][j])>2)){
  59. for (a = j; a < m - 1; a++){
  60. for (b = 0; b < n; b++){
  61. matr[b][a] = matr[b][a + 1];
  62. }
  63. }
  64. j--;
  65. m--;
  66. }
  67. i++;
  68. prost = 0;
  69. }
  70.  
  71. i = 0;
  72.  
  73. j++;
  74. }
  75.  
  76. cout << endl;
  77. cout << "Матрица после обработки : " << endl;
  78. cout << endl;
  79. Print_Matr(matr, n, m);
  80. }
  81.  
  82.  
  83. void main()
  84. {
  85. int n, m, i = 0, j = 0;
  86. setlocale(LC_ALL, "rus");
  87. cout << "Введите кол-во столбцов в двумерном массиве" << endl;
  88. cin >> n;
  89. cout << "Введите кол-во строк в двумерном массиве" << endl;
  90. cin >> m;
  91. time_t t;
  92. srand((unsigned)time(&t));
  93. int** matr = form_matr(n, m);
  94. cout << "Исходная матрица : " << endl;
  95. Print_Matr(matr, n, m);
  96. delete_str(matr, n, m);
  97. }
Advertisement
Add Comment
Please, Sign In to add comment