Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include<iostream>
  2. #include<time.h>
  3. #include<cstdlib>
  4. #include <iomanip>
  5. using namespace std;
  6.  
  7.  
  8. int ileWystapien(int dane[], int dl, int a) {
  9. int licznik = 0;
  10. for (int i = 0; i < dl; i++) {
  11. if (dane[i] == a) {
  12. licznik++;
  13. }
  14. }
  15. return licznik;
  16. }
  17. void swap(int *xp, int *yp)
  18. {
  19. int temp = *xp;
  20. *xp = *yp;
  21. *yp = temp;
  22. }
  23.  
  24. void bubbleSort(int arr[], int n)
  25. {
  26. int i, j;
  27. for (i = 0; i < n-1; i++)
  28.  
  29. for (j = 0; j < n-i-1; j++)
  30. if (arr[j] > arr[j+1])
  31. swap(&arr[j], &arr[j+1]);}
  32.  
  33. int main()
  34. {
  35. srand(time(NULL));
  36. int n,N;
  37. cout<<"Ilosc liczb :";
  38. cin>>n;
  39. cout<<" \n\n";
  40. cout<<"Wybierz zakres losowanych liczb, od 1 do: ";
  41. cin>>N;
  42. cout<<" \n\n ";
  43. int A[n];
  44. cout<<"Wylosowane liczby: \n\n ";
  45. for(int i=0;i<n;i++){
  46.  
  47. A[i]=rand()%N;
  48. cout<<A[i]<<setw(5);
  49. if(i>0 && i%10==0) cout<<endl;}
  50. cout<<" \n\n";
  51. bubbleSort(A,n);
  52. cout<<"Posortowane liczby: \n\n ";
  53. for(int i=0;i<n;i++){
  54. cout<<A[i]<<setw(5);
  55. if(i>0 && i%10==0) cout<<endl;}
  56. cout<<"\n\n";
  57. for(int i=1;i<=N;i++){
  58. cout<<"liczba "<<i<<" wystepuje "<<ileWystapien(A,n,i);
  59. cout<<" razy "<<endl; }
  60.  
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement