Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- bool remove(int nrs[], int& nrOf, int toBeRemoved);
- int main() {
- int numbers[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
- int cap = 8;
- remove(numbers, cap, 5);
- #ifdef _DEBUG
- system("pause");
- #endif // _DEBUG
- return 0;
- }
- bool remove(int nrs[], int& nrOf, int toBeRemoved) {
- int temp = nrOf;
- for (int i = 0; i < nrOf; i++) {
- if (nrs[i] == toBeRemoved) {
- for (int j = i; j < nrOf; j++) {
- if (j < nrOf) nrs[j] = nrs[j + 1];
- }
- nrOf--;
- }
- }
- for (int i = 0; i < nrOf; i++) {
- cout << nrs[i] << endl;
- }
- if (nrOf < temp) {
- return true;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment