Referred From : GURUPRASAD M S
#include<stdio.h>
#include<stdlib.h>
int a[10],n,i,position,value;
void create();
void display();
void insert();
void delete();
void main()
{
int choice;
while(1)
{
printf("Press 1.CREATE \t 2.DISPLAY \t 3.INSERT \t 4.DELETE \t 5.Exit \n");
printf("Enter your choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1: create(); break;
case 2:display(); break;
case 3:insert(); break;
case 4:delete();break;
case 5: exit(0); break;
default: printf("Invalid Choice\n"); break;
}
}
}
void delete()
{
printf("\nEnter the position of the element to be deleted:\t");
scanf("%d",&position);
for(i=position;i<n-1;i++)
{
a[i]=a[i+1];
}
n=n-1;
display();
}
void insert()
{
printf("Enter the position of new value to Insert\n");
scanf("%d",&position);
printf("Enter the new value to Insert\n");
scanf("%d",&value);
for(i=n-1;i>=position;i--)
{
a[i+1]=a[i];
}
a[position]=value;
n=n+1;
display();
}
void display()
{
printf("Array Values are:\n");
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
}
void create()
{
printf("Enter the size of the array elements\n");
scanf("%d",&n);
printf("Enter the array values\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
}
OUTPUT:
Referred From : PRITHVIRAJ JAIN
#include<stdio.h>
#include<stdlib.h>
void create();
void display();
void insert();
void delete();
int i,n,j,a[10],ele,pos,choice;
void main()
{
while(1)
{
printf("\n\n--------MENU--------\n\n");
printf("1. CREATE\n\n");
printf("2. DISPLAY\n\n");
printf("3. INSERT\n\n");
printf("4. DELETE\n\n");
printf("5. EXIT\n\n");
printf("ENTER YOUR CHOICE : \n");
scanf("%d",&choice);
switch(choice)
{
case 1:create();
break;
case 2:display();
break;
case 3:insert();
break;
case 4:delete();
break;
case 5:exit(0);
default:printf("INVALID CHOICE\n");
}
}
}
void create()
{
printf("ENTER THE NO. OF ELEMENTS : \n");
scanf("%d",&n);
printf("ENTER % d ELEMENTS INTO ARRAY \n",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
}
void display()
{
printf("THE ARRAY ELEMENTS ARE : \n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
}
void insert()
{
printf("ENTER THE ELEMENT TO BE INSERTED :\n");
scanf("%d",&ele);
printf("ENTER THE POSITION TO BE INSERTED :\n");
scanf("%d",&pos);
for(i=n-1;i>=pos;i--)
a[i+1]=a[i];
a[pos]=ele;
n=n+1;
}
void delete()
{
printf("ENTER THE POSITION TO BE DELETED :\n");
scanf("%d",&pos);
ele=a[pos];
for(i=pos;i<n-1;i++)
a[i]=a[i+1];
n=n-1;
printf("THE DELETED ELEMENT IS :%d\n",ele);
}