Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <locale>
  3.  
  4. using namespace std;
  5. int arrayUnique(int *ar, int size)
  6. {
  7. for (int i = 0; i < size; i++){
  8. for (int j = i + 1; j < size; j++){
  9. if (ar[i] == ar[j]){
  10. for (int shift = j; shift < size - 1; shift++){
  11. ar[shift] = ar[shift + 1];
  12. }
  13. size -= 1;
  14. if (ar[i] == ar[j]){
  15. j--;
  16. }
  17. }
  18. }
  19. }
  20. return size;
  21. }
  22. int main(int argc, char* argv[])
  23. {
  24. int arr [200];
  25. int n;
  26. cout << "Vvedite kolichestvo elementov v masive: ";
  27. cin >> n;
  28. cout << "Vvedite elemeti masiva:";
  29. for (int i = 0; i < n; i++){
  30. cin >> arr[i];
  31. }
  32. cout << "\n";
  33.  
  34. for (int i = 0; i < arrayUnique(arr, n); i++){
  35. cout << arr[i] << " ";
  36. }
  37. cout << endl;
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement