Answer to Question #262538 in C++ for Korea

Question #262538

Write aprogramm using Array 1,2,3,4,5 and insert middle 5,6 and delete 3

1
Expert's answer
2021-11-07T15:54:29-0500
#include <iostream>
using namespace std;
void insert(int *arr, int n, int val) {
  arr[n++] = val; 
} 
void remove(int *arr, int val) {
  int n = (int) sizeof(arr) / sizeof(int);
  for (int i=0, j=0; j < n; j++) {
    if (arr[j] != val)
      arr[i++] = arr[j];
  }
}
int main() {
  int arr[10] = {1,2,3,4,5};
  insert(arr, 5, 5);
  insert(arr, 6, 6);
  remove(arr, 3);
  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS