botgob

Untitled

Nov 22nd, 2019
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. bool remove(int nrs[], int& nrOf, int toBeRemoved);
  6.  
  7. int main() {
  8. int numbers[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
  9. int cap = 8;
  10. remove(numbers, cap, 5);
  11.  
  12.  
  13.  
  14.  
  15. #ifdef _DEBUG
  16. system("pause");
  17. #endif // _DEBUG
  18.  
  19. return 0;
  20. }
  21.  
  22. bool remove(int nrs[], int& nrOf, int toBeRemoved) {
  23. int temp = nrOf;
  24. for (int i = 0; i < nrOf; i++) {
  25. if (nrs[i] == toBeRemoved) {
  26. for (int j = i; j < nrOf; j++) {
  27. if (j < nrOf) nrs[j] = nrs[j + 1];
  28. }
  29. nrOf--;
  30. }
  31. }
  32. for (int i = 0; i < nrOf; i++) {
  33. cout << nrs[i] << endl;
  34. }
  35. if (nrOf < temp) {
  36. return true;
  37. }
  38. return false;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment