-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path1. Array-Operation.c
65 lines (59 loc) · 1.26 KB
/
1. Array-Operation.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
#include<stdio.h>
#include<stdlib.h>
int a[10], n,i;
void create() {
printf("Enter the number of elements :");
scanf("%d",&n);
printf("Enter the element in the array :");
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
}
void display() {
printf("Elements in the Array are :");
for(i=0;i<n;i++){
printf("%d",a[i]);
printf(" ");
}
}
int elem ,pos;
void insert(){
printf("Enter the position for new element : ");
scanf("%d",&pos);
printf("Enter the element to be inserted : ");
scanf("%d",&elem);
for (i=n-1;i>=pos-1;i--){
a[i+1]=a[i];
}
a[pos-1]=elem;
n=n+1;
}
void delete(){
printf("Enter the position to delete :");
scanf("%d",&pos);
printf("Deleted element is %d", a[pos-1]);
for(i=pos;i<=n-1;i++){
a[i-1]=a[i];
}
n=n-1;
}
int main(){
int ch;
while(1)
{
printf("\n____ARRAY OPERATION____\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;
}