Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.57 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include "locale.h"
  4. #define m 10
  5. #define n 10
  6. using namespace std;
  7. bool noSwap;
  8. void vvod_arr(int h, int x[])
  9. {
  10. int i, l;
  11. cout « "Введите количество элементов массива" « endl;
  12. cin » l;
  13. cout « "Ввод массива" « endl;
  14. for (i = 0; i < l; i++)
  15. {
  16. cin » x[i];
  17. }
  18. }
  19. int vvod_arr_rand(int h, int x[])
  20. {
  21. int i;
  22. for (i = 0; i < h; i++)
  23. {
  24. x[i] = -10000 + rand() % 20000;
  25. cout « x[i] « " ";
  26. }
  27. cout « endl;
  28. return 0;
  29. }
  30.  
  31. void vivod_arr(int h, int x[])
  32. {
  33. int i;
  34. cout « "Вывод массива" « endl;
  35. for (i = 0; i < h; i++)
  36. {
  37. cout « x[i] « " ";
  38. }
  39. }
  40. void por(int h, int x[])
  41. {
  42. int i, tmp, j = 0;
  43. for (i = h - 1; i >= 0; i--)
  44. {
  45. noSwap = 1;
  46. for (j = 0; j < i; j++)
  47. {
  48. if (x[j] > x[j + 1])
  49. {
  50. tmp = x[j];
  51. x[j] = x[j + 1];
  52. x[j + 1] = tmp;
  53. noSwap = 0;
  54. }
  55. }
  56. if (noSwap == 1)
  57. {
  58. break;
  59. }
  60. }
  61. }
  62. int _tmain(int argc, _TCHAR* argv[])
  63. {
  64. int a[n], b[m], k;
  65. setlocale(LC_ALL, "rus");
  66. cout « "Для ввода массива с клавиатуры введите 1, для ввода случайных чисел нажмите 0" « endl;
  67. cin » k;
  68. //Ввод массива
  69. if (k == 1)
  70. {
  71. vvod_arr(n, a);
  72. vvod_arr(m, b);
  73. }
  74. else
  75. {
  76. vvod_arr_rand(n, a);
  77. vvod_arr_rand(m, b);
  78. }
  79. //Упорядочивание массива от меньшего к большему
  80. por(n, a);
  81. por(m, b);
  82. //Вывод массива
  83. vivod_arr(n, a);
  84. cout « endl;
  85. vivod_arr(m, b);
  86. return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement