Advertisement
nhbao

Untitled

Apr 9th, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. void SapXep(int a[], int n)
  2. {
  3.     for (int i=0;i<n;i++)
  4.         for (int j = i+1; j < n; j++)
  5.         {
  6.             if (a[i] > a[j]) swap(a[i], a[j]);
  7.         }
  8. }
  9. int DemSoLan(int a[], int n)
  10. {
  11.     int dem = 1;
  12.     for (int i = 0; i < n; i++)
  13.     {
  14.         if (a[i] == a[i + 1])
  15.         {
  16.             dem++;
  17.         }
  18.         else if (a[i] != a[i + 1])
  19.         {
  20.             cout << "so lan xuat hien cua " << a[i] << " la: " << dem << endl;
  21.             dem = 1;
  22.         }
  23.     }
  24.     return dem;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement