Thursday 29 August 2013

Program In C For Insertion and deletion of numbers to an array.


#include<stdio.h>
#include<conio.h>
void main()
{
int n,c,choice,value,pos,A[50];
clrscr();
printf("enter the number of elements in A");
scanf("%d",&n);
printf("Enter the %d elements\n",n);
for(c=0;c<n;c++)
scanf("%d",&A[c]);
printf("1.Insertion\t2.Deletion");
scanf("%d",&choice);
if(choice==1)
{
printf("Enter the location where you wish to insert element");
scanf("%d",&pos);
printf("enter the value to insert");
scanf("%d",&value);
for(c=n-1;c>=pos-1;c--)
A[c+1]=A[c];
A[pos-1]=value;
printf("A is ");
for(c=0;c<=n;c++)
printf("%d\t",A[c]);

}
else if(choice==2)
{
printf("Enter the location where you wish to delete element");
scanf("%d",&pos);
if(pos>=n+1)
printf("Deletion not possible");
for(c=pos-1;c<n;c++)
A[c]=A[c+1];
printf("A after delition is  ");
for(c=0;c<n-1;c++)
printf("%d\t",A[c]); }
else

printf(“Wrong Choice !!!!”);
getch();
}