ChameL1oN

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

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