-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path1.Array.c
More file actions
84 lines (84 loc) · 1.97 KB
/
1.Array.c
File metadata and controls
84 lines (84 loc) · 1.97 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
/*To create ,display,insert and delete*/
#include<stdio.h>
#include<stdlib.h>
#define MAX 5
int a[MAX],f=0,n,i,p;
void create(){
printf("\nEnter no. of elements\n");
scanf("%d",&n);
if(n>MAX){
printf("The no. of elements inserted cannot be greater than max'm size %d",MAX);
return;
}
printf("\nEnter the elements\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
f=1;
}
void display(){
if(f==0){
printf("Array not created");
return;
}
if(n==0){
printf("\nArray Empty\n");
return;
}
printf("\nThe elements are\n");
for(i=0;i<n;i++)
printf("%d ",a[i]);
}
void delete(){
if(f==0){
printf("Array not created");
return;
}
if(n==0){
printf("\nArray Empty\n");
return;
}
printf("\nEnter position to delete\n");
scanf("%d",&p);
p=p-1;//To get the index corresponding to the position
for(i=p;i<n-1;i++)
a[i]=a[i+1];
n=n-1;//Update the size of the array
}
void insert(){
if(f==0){
printf("Array not created");
return;
}
int e;
if(n==MAX){
printf("\nArray FULL\n");
return;
}
printf("\nEnter element and position to insert\n");
scanf("%d%d",&e,&p);
p=p-1;//To get the index corresponding to the position
for(i=n;i>p;i--)
a[i]=a[i-1];
a[p]=e;
n=n+1;//Update array's size
}
int main(){
int ch;
printf("\nMENU:\n1.Create\n2.Display\n3.Delete\n4.Insert\n5.Exit\n");
while(1){
printf("\nEnter your choice\n");
scanf("%d",&ch);
switch(ch){
case 1: create();
break;
case 2: display();
break;
case 3: delete();
break;
case 4: insert();
break;
case 5: exit(0);
break;
}
}
}