ChameL1oN

Лаба5_Задача_2

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