Untitled
unknown
plain_text
a year ago
1.5 kB
10
Indexable
#include <stdio.h>
#include <conio.h>
int arr[50],pos,data,i,ch,size,val;
void create();
void insert();
void delete();
void display();
void main() {
clrscr();
do{
printf("\n\n-----MENU------\n\n");
printf("\n1.Create.");
printf("\n2.Display.");
printf("\n3.Delete.");
printf("\n4.Insert.");
printf("\n5.Exit.");
printf("\n--------------");
printf("\nEnter your choice:");
scanf("%d",&ch);
switch(ch) {
case 1:create();
break;
case 2:display();
break;
case 3:delete();
break;
case 4:insert();
break;
case 5:exit();
break;
default:printf("\nInvalid Choice");
break;
}
} while(ch!=0);
getch();
}
void create(){
printf("\nEnter the size of array:");
scanf("%d",&size);
printf("\nEnter the elements of the array:");
for(i=0;i<size;i++) {
scanf("%d",&arr[i]);
}
}
void insert(){
printf("\nEnter the position of the element:");
scanf("%d",&pos);
printf("\nEnter the element to be inserted:");
scanf("%d",&data);
for(i=size;i>=pos;i++){
arr[i]=arr[i-1];
}
arr[i]=data;
size=size+1;
}
void delete(){
printf("\nEnter the position of the element to be deleted:");
scanf("%d",&pos);
val=arr[pos-1];
for(i=pos-1;i<size;i++){
arr[i]=arr[i+1];
}
size=size-1;
printf("\nThe deleted element is=%d",val);
}
void display(){
printf("\nThe elements of the array are:");
for(i=0;i<size;i++){
printf("\t%d",arr[i]);
}
}Editor is loading...
Leave a Comment