INSERT ELEMENT
#include<stdio.h>
void main()
{
int n,i,a[100],position,value;
printf("Enter the array size\n");
scanf("%d",&n);
printf("Enter the %d elements in the array\n",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter the element you have to insert\n");
scanf("%d",&position);
printf("Enter the value to insert\n");
scanf("%d",&value);
for(i=n-1;i>=position-1;i--)
a[i+1]=a[i];
a[position-1]=value;
printf("The sorted array is\n");
for(i=0;i<=n;i++)
printf("%d\n",a[i]);
}
OUTPUT:
#include<stdio.h>
void main()
{
int n,i,a[100],position,value;
printf("Enter the array size\n");
scanf("%d",&n);
printf("Enter the %d elements in the array\n",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter the element you have to insert\n");
scanf("%d",&position);
printf("Enter the value to insert\n");
scanf("%d",&value);
for(i=n-1;i>=position-1;i--)
a[i+1]=a[i];
a[position-1]=value;
printf("The sorted array is\n");
for(i=0;i<=n;i++)
printf("%d\n",a[i]);
}
OUTPUT: