HOT C PROGRAMS BLOGSPOT

HOT C PROGRAMS BLOGSPOT

Click On Related Results For More Information

Wednesday 3 October 2012

Array Insert Delete Update Display Exit

#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{clrscr();
int num,array[10],ch,i,a,p,f,x,dp;
printf("How many numbers you want to enter in array(maximum 10)?\n");
scanf("%d",&num);
printf("Enter the numbers\n");
for(i=0;i<num;i++)
scanf("%d",&array[i]);
char tr='y';
do
{
printf("\n1.Insert\n2.Delete\n3.Display\n4.Exit\n");
printf("\nEnter your choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
if(num==10)
printf("\noverflow condition.");
else
{
printf("\nWhich number you want to insert?\n");
scanf("%d",&a);
printf("\nin Which position you want to enter the number?\n");
scanf("%d",&p);
x=num;
for(i=x;i>p-1;i--)
array[i]=array[i-1];
array[p-1]=a;
num=num+1;
}
break;
}
case 2:
{ if(num==0)
printf("\nunderflow condition.");
else
{
printf("\nGive the position of the item which you want to delete.\n");
scanf("%d",&dp);
printf("\nThe deleted item is %d",array[dp-1]);
for(i=dp-1;i<num;i++)
array[i]=array[i+1];
num=num-1;
}
}
case 3:
{
printf("\n");
for(i=0;i<10;i++)
printf("----");
printf("\n");
for(i=0;i<num;i++)
{
if(array[i]>9&&array[i]<100)
printf("| %d",array[i]);
if(array[i]<10)
printf("|  %d",array[i]);
if(array[i]>99)
printf("|%d",array[i]);
}
for(f=num;f<10;f++)
printf("|   ");
printf("|\n");
for(i=0;i<10;i++)
printf("----");
break;
}
case 4:
exit(1);
}
printf("\nDo you want to enter another choice?press y for yes.\n");
scanf("%c",&tr);
scanf("%c",&tr);
}while(tr=='y');
getch();

No comments:

Post a Comment