ChameL1oN

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

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