-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathARRAY.c
71 lines (65 loc) · 1.26 KB
/
ARRAY.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include<stdio.h>
#include<stdlib.h>
int a[10],n,elem,i,pos;
void create();
void display();
void insert();
void delete();
void create()
{
int i;
printf("Enter the size of array\n");
scanf("%d",&n);
printf("Enter the elements of array\n");
for(i=0; i<n; i++)
scanf("%d",&a[i]);
}
void display()
{
int i;
printf("The array elements are:\n");
for(i=0; i<n; i++)
printf("%d\t",a[i]);
}
void insert()
{
int i;
printf("Enter the position for new element:\n");
scanf("%d",&pos);
printf("Enter the element to be inserted:\n");
scanf("%d",&elem);
for (i = n-1; i <=pos; i--)
a[i+1]=a[i];
a[pos]=elem;
n=n+1;
}
void delete()
{
printf("Enter position of element to be deleted:\n");
scanf("%d",&pos);
elem=a[pos];
for (int i = 0; i < n-1; i++)
a[i]=a[i+1];
n=n-1;
printf("Deleted element is %d\n",elem );
}
int main()
{
int ch;
while(ch)
{
printf("\n\n______MENU_____\n");
printf("1.Create\n2.Display\n3.Insert\n4.Delete\n5.Exit\n");
printf("Enter Your Choice:");
scanf("%d",&ch);
switch(ch)
{
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");
}
}return 0;
}