Write a C program to insert an element at desired position.
#include<stdio.h>
#include<conio.h>
int main()
{ clrscr();
int arr[100] = { 0 };
int i, x, pos, n;
printf("Enter the elements you want to enter");
scanf("%d",&n);
printf("Enter the elements");
for (i = 0; i < n; i++)
scanf("%d", &arr[i]);
arr[i] = i + 1;
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
printf("Enter the element you want to enter");
scanf("%d", &x);
printf("Enter the desired position of your choice");
scanf("%d", &pos);
n++;
for (i = n; i >= pos; i--)
arr[i] = arr[i-1];
arr[pos - 1] = x;
for (i = 0; i < n; i++)
printf("%d ", arr[i]);
printf("\n");
getch();
}
0 Comments
Have any query? Want any type of module?
Please comment it down and let me know.