ChameL1oN

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

Dec 17th, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 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(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 = 1;
  51. int** matr_new = form_matr(n, m);
  52. while (j < m){
  53. while (i <= n-1){
  54.  
  55. matr_new[i][j] = matr[k][j];
  56. i++;
  57. k += 2;
  58. }
  59. i = 0;
  60. k = 1;
  61. j++;
  62. }
  63. cout << endl;
  64. cout << "Матрица после обработки : " << endl;
  65. cout << endl;
  66. Print(matr_new, n, m);
  67. }
  68.  
  69.  
  70. void main()
  71. {
  72. int n, m, i = 0, j = 0;
  73. setlocale(LC_ALL, "rus");
  74. cout << "Введите кол-во столбцов в двумерном массиве" << endl;
  75. cin >> n;
  76. cout << "Введите кол-во строк в двумерном массиве" << endl;
  77. cin >> m;
  78. time_t t;
  79. srand((unsigned)time(&t));
  80. int** matr = form_matr(n, m);
  81. cout << "Исходная матрица : " << endl;
  82. Print(matr, n, m);
  83. delete_str(matr, n/2, m);
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment