Skip to main content

Normal Insert by Using Function in C

	#include<stdio.h>
	#include<conio.h>
	#include<stdlib.h>
	#include<dos.h>

	void TAKING_VALUE(int DATA[50],int x)
		{
		int i;
		for(i=1;i<=x;i++)
			{
			printf("DATA[%d]=",i);
			scanf("%d",&DATA[i]);
			}
		}

	void INSERT(int DATA[50],int x)
		{
		int loc,v,i,k,t;
		INSERT:
		printf("\nENTER LOCATION TO INSERT:\t");
		scanf("%d",&loc);
		if(loc>x)
		      {
		      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<=x+1;i++)
			{
			if(loc==i)
				{
				for(k=i;k<=x+1;k++)
					{
					t=DATA[k];
					DATA[k]=v;
					v=t;
					}
				}
			printf("\nDATA[%d]=%d",i,DATA[i]);
			}
		}

	void main()
		{
		int i,n,k,t,DATA[50],loc,v;
		char c;
		clrscr();
		printf("HOW MANY ELEMENT YOU WANT:\t");
		scanf("%d",&n);
		TAKING_VALUE(DATA,n);
		AGAIN:
		INSERT(DATA,n);
		printf("\nINSERT AGAIN ? (y/n)..");
		c=getch();
		if(c=='y'||c=='Y')
			{
			n=n+1;
			goto AGAIN;
			}
		else
			{
			printf("\n\n\t\t****** GOOD BYE ******");
			delay(2000);
			exit(1);
			}
		}
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 *