Skip to main content

Multi-Insert by Using Function in C

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
void READ_VALUE(int data[50],int n1)
	{
	int i;
	for(i=1;i<=n1;i++)
		{
		printf("data[%d]= ",i);
		scanf("%d",&data[i]);
		}
	}
void MULTI_INSERT(int data[50],int n1,int l,int n2)
	{
	int i,j,a[50];
	for(i=1;i<=n2;i++)
		{
		printf("a[%d]= ",i);  scanf("%d",&a[i]);
		}
		//shifting//
	for(i=(n1+n2),j=0;i>=n2+l;i--,j++)
		{
		data[i]=data[n1-j];
		}
		//entering value//
	for(i=0;i<n2;i++)
		{
		data[l+i]=a[i+1];
		}
		//display//
	for(i=1;i<=n1+n2;i++)
		{
		printf("data[%d]=%d\n",i,data[i]);
		}
	}

void main()
	{
	clrscr();
	int n1,n2,l,data[50];
	char c;
	printf("how many element u want:\t");	scanf("%d",&n1);
	READ_VALUE(data,n1);
	again:
	printf("\nEnter location to insert:\t");  scanf("%d",&l);
	printf("\nHow many element u want:\t");   scanf("%d",&n2);
	MULTI_INSERT(data,n1,l,n2);
	printf("\nInsert again ? (y/n)..");
	c=getch();
	if(c=='y')
		{
		n1=n1+n2;
		goto again;
		}
	else
		exit(0);
	}
Spread the love

Mashkawat Ahsan

I am Mashkawat Ahsan. Wikipedian, Mozillian, tech activist, art lover. Thank you for visiting.

Leave a Reply

Your email address will not be published. Required fields are marked *