Create a c++ code using arrays and array insertion to display the required output below.…
- User
Create a c++ code using arrays and array insertion to display the required output below.
Output: The original array elements are: LA[0] = 3 LA[1] = 1 LA[2] = 2 LA[3] = 4 LA[4] = 9
The array elements after insertion: LA[0] = 3 LA[1] = 1 LA[2] = 11 LA[3] = 2 LA[4] = 4 LA[5] = 9
- Assistant
#include using namespace std;
int main() { int LA[6] = {3, 1, 2, 4, 9}; int n = 5; int k = 2;
cout << "The original array elements are:" << endl; for (int i = 0; i < n; i++) { cout << "LA[" << i << "] = " << LA[i] << endl; }
// Inserting an element at index k for (int j = n; j >= k; j--) { LA[j] = LA[j-1]; } LA[k] = 11; n++;
cout << endl; cout << "The array elements after insertion:" << endl; for (int i = 0; i < n; i++) { cout << "LA[" << i << "] = " << LA[i] << endl; }
return 0; }