Advertisement
Domerk

Массив с сортировкой

Dec 27th, 2011
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. // Массив длинной 1000 чисел. Выводится, сортируется, снова выводится.
  2.  
  3. #include <iostream>
  4. #include <cstdlib>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.      srand(time(NULL))
  10.      int m[1000], i;
  11.      for (i=0; i<=999; i++)
  12.           m[i]=rand();
  13.  
  14.      outmass (m, 1000);
  15.      sortmass (m, 1000);
  16.      outmass (m, 1000);
  17.  
  18.      cin.sync();
  19.      cin.clar();
  20.      cin.get();
  21.      return 0;
  22. }
  23.  
  24. void outmass(int massiv[], int save)
  25. {
  26.      for (int i=0; i<save; i++)
  27.           cout<<massiv[i];
  28. }
  29.  
  30. void sortmass(int massiv[], int save)
  31. {
  32.      for (int f=0; f<save; f++)
  33.           for (int t=0; t<=save-f; t++)
  34.                if (massiv [t]>massiv[t+1]
  35.                zam (massiv [t], massiv [t+1]);
  36. }
  37.  
  38. void zam (int &a, int &b)
  39. {
  40.      int x;
  41.      x = a;
  42.      a = b;
  43.      b = x;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement