Skip to main content

Normal Insert in C

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<dos.h>
void main()
	{
	int i,n,k,t,DATA[50],loc,v;
	char c;
	clrscr();
	printf("HOW MANY ELEMENT YOU WANT:\t");
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		{
		printf("DATA[%d]=",i);	scanf("%d",&DATA[i]);
		}
	INSERT:
	printf("\nENTER LOCATION TO INSERT:\t");  scanf("%d",&loc);
	if(loc>n)
		{
		printf("\n\aSORRY OOCATION IS OUT OF RANGE. TRY AGAIN...");
		goto INSERT;
		}
	printf("\nENTER VALUE:\t");  scanf("%d",&v);
	printf("\nAFTER INSERT..");
	for(i=1;i<=n+1;i++)
		{
		if(loc==i)
			{
			for(k=i;k<=n+1;k++)
				{
				t=DATA[k];
				DATA[k]=v;
				v=t;
				}
			}
		printf("\nDATA[%d]=%d",i,DATA[i]);
		}
	printf("\nINSERT AGAIN ? (y/n)..");
	c=getch();
	if(c=='y'||c=='Y')
		{
		n=n+1;
		goto INSERT;
		}
	else
		{
		printf("\n\n\t\t****** GOOD BEY ******");
		delay(2500);
		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 *