Complete the code to shift elements right before inserting at the beginning.
for(int i = n - 1; i >= [1]; i--) { arr[i + 1] = arr[i]; }
We shift elements starting from the last index down to 0 to make space at the beginning.
Complete the code to insert the new element at the beginning of the array.
arr[[1]] = new_element;The new element is inserted at index 0, the beginning of the array.
Fix the error in the loop condition to correctly shift elements for insertion.
for(int i = n - 1; i [1] 0; i--) { arr[i + 1] = arr[i]; }
The loop must run while i is greater than or equal to 0 to shift all elements.
Fill both blanks to correctly shift elements and insert at the beginning.
for(int i = n - 1; i [1] [2]; i--) { arr[i + 1] = arr[i]; }
The loop runs while i is greater than or equal to 0 to shift all elements starting from the last index.
Fill all three blanks to complete the insertion function at the beginning of the array.
void insertAtBeginning(int arr[], int n, int new_element) {
for(int i = n - 1; i [1] [2]; i--) {
arr[i + 1] = arr[i];
}
arr[[3]] = new_element;
}The loop shifts elements while i >= 0, and the new element is inserted at index 0.
