Advertisement
Guest User

kubełkowe

a guest
May 20th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. srand (time ( NULL));
  10. int n = 0;
  11. while (n < 1)
  12. {
  13. cout << "Podaj rozmiar tablicy: ";
  14. cin >> n;
  15. }
  16.  
  17. int* T = new int[n];
  18. int losowa;
  19.  
  20. for(int i = 0; i < n; i++)
  21. {
  22. losowa = (rand() %31) + 0;
  23. T[i] = losowa;
  24. cout << T[i] << " ";
  25. }
  26.  
  27. int P[31];
  28. for(int i = 0; i < 32; i++)
  29. {
  30. P[i] = 0;
  31. }
  32. for(int i = 0; i < n; i++)
  33. {
  34. P[ T[i] ] ++;
  35.  
  36. }
  37.  
  38. int x = 0;
  39. for(int i = 0; i != 31; i++)
  40. {
  41. for (int j = 0; j != P[i]; j++)
  42. {
  43. T[x] = i;
  44. x++;
  45. }
  46. }
  47.  
  48. cout<<endl;
  49. for(int f = 0; f < n; f++){
  50. cout << T[f] << " ";
  51. }
  52.  
  53. delete[] T;
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement