Write a program to show the concept of Merging in Data structure
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],n,k,i,j,item;
printf("enter n=");
scanf("%d",&n);
printf("enter array elements=");
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
printf("enter element to be inserted=");
scanf("%d",&item);
printf("enter location of new element=");
scanf("%d",&k);
j=n;
while(j>=k)
{
a[j+1]=a[j];
j--;
}
a[k]=item;
n=n+1;
printf("\nnew array is\n");
for(i=1;i<=n;i++)
{
printf("%d\n",a[i]);
}
}
#include<conio.h>
void main()
{
int a[10],n,k,i,j,item;
printf("enter n=");
scanf("%d",&n);
printf("enter array elements=");
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
printf("enter element to be inserted=");
scanf("%d",&item);
printf("enter location of new element=");
scanf("%d",&k);
j=n;
while(j>=k)
{
a[j+1]=a[j];
j--;
}
a[k]=item;
n=n+1;
printf("\nnew array is\n");
for(i=1;i<=n;i++)
{
printf("%d\n",a[i]);
}
}
Comments
Post a Comment