ChameL1oN

Лаба5_Задача2(Вар.27)

Dec 12th, 2014
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 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 n, int m){
  29. int r, a = 0, b = 0;
  30. while (b < m){
  31. if (b % 2 == 1){
  32. while (a < n / 2){
  33. r = matr[a][b];
  34. matr[a][b] = matr[n - 1 - a][b];
  35. matr[n - 1 - a][b] = r;
  36. a++;
  37. }
  38. }
  39. a = 0;
  40. b++;
  41.  
  42. }
  43. cout << "После обработки строк :" << endl;
  44. r = 0;
  45. a = 0;
  46. while (r < m){
  47. while (a < n){
  48. cout << setw(6) << matr[a][r] << " ";
  49. a++;
  50. }
  51. a = 0;
  52. cout << endl;
  53. r++;
  54. }
  55. }
  56.  
  57. void main()
  58. {
  59. int stolb, strok, i = 0, j = 0;
  60. setlocale(LC_ALL, "rus");
  61. cout << "Введите кол-во столбцов в двумерном массиве" << endl;
  62. cin >> stolb;
  63. cout << "Введите кол-во строк в двумерном массиве" << endl;
  64. cin >> strok;
  65. time_t t;
  66. srand((unsigned)time(&t));
  67. int** matr = form_matr(stolb, strok);
  68. while (j < strok){
  69. while (i < stolb){
  70. cout << setw(6) << matr[i][j] << " ";
  71. i++;
  72. }
  73. i = 0;
  74. cout << endl;
  75. j++;
  76. }
  77. perevorot(matr, stolb, strok);
  78. }
Advertisement
Add Comment
Please, Sign In to add comment