#include<stdio.h>
#include<conio.h>
void
main()
{
int a[20]={0},i,j,ct,lim,pos,num,opt,val;
int n,temp,fl=0;
clrscr();
printf("\n\t\tARRAY
OPERATIONS");
printf("\n\n Enter
the limet of array:");
scanf("%d",&lim);
n=lim;
men:
clrscr();
printf("\n\t MENU:");
printf("\n\t ~~~~~");
printf("\n\t1.CREATE");
printf("\n\t2.VIEW");
printf("\n\t3.INSERT");
printf("\n\t4.DELETE");
printf("\n\t5.EXIT");
printf("\nEnter
the option:");
scanf("%d",&opt);
switch(opt)
{
case 1:
printf("\nEnter
the No of values(if<%d):",lim);
scanf("%d",&n);
if(n>lim)
{
printf("You must enter value is <%d",lim);
getch();
goto men;
}
else
{
printf("\nEnter the %d values:",n);
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
goto
men;
}
case 2:
printf("\nArray
values are:");
for(i=1;i<=n;i++)
printf("\n%d",a[i]);
getch();
goto
men;
case 3:
printf("Enter
the position insert:(position <%d)",lim);
scanf("%d",&pos);
if(pos>lim)
{
printf(" \n you must enter the value <
%d",lim);
getch();
goto men;
}
else
{
printf("Enter
the value to insert:");
scanf("%d",&val);
if(pos<=n)
{
for(i=n+1;i>pos;i--)
a[i]=a[i-1];
a[pos]=val;
n=n+1;
}
else
{
a[n+1]=val;
n++;
}
}
goto
men;
case 4:
if(n<=0)
{
printf("\nArray is empty");
getch();
goto men;
}
printf("\nEnter
the value to delete :");
scanf("%d",&pos);
i=1;ct=0;
while(i<=n)
{
if(pos==a[i])
{
n--;
for(j=i;j<=n;j++)
a[j]=a[j+1];
fl=1;
printf("%d is deleted",pos);
}
else
i++;
}
if(fl==0)
printf(" The value not in array");
goto
men;
case 5:
exit();
break;
}
getch();
}
No comments:
Post a Comment