ChameL1oN

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

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