My issue
give the code
My code
#include<bits/stdc++.h>
using namespace std;
int main() {
int n = 6; // Initial array
int arr[10] = {
4,
5,
3,
10,
12,
18
}; // Current size of the array
int newPosition = 5; // Index where you want to insert the new element
int newElement = 7; // Element to be inserted
// Shift elements to make space for the new element
for (int i = n; i > index; i--) {
arr[i] = arr[i - 1];
}
// Insert the new element at the specified position
arr[index] = newElement;
// Update the size of the array
n++;
// Print the updated array
for (int i = 0; i < n; i++) {
printf("%d", arr[i]);
}
}
Learning course: Data structures & Algorithms lab
Problem Link: https://www.codechef.com/learn/course/muj-aiml-dsa-c/MUJADSAC05/problems/DSAAGP07A