-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArray.c
138 lines (129 loc) · 2.2 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include<stdio.h>
int f=0,n,a[10],i,e,op,ad,ans;
void input();
void insert(int,int);
void delete(int);
int search();
void display();
void main()
{
do
{
printf("Select your operation:\n1.Input\n2.Insert Element\n3.Delete Element\n4.Search Element\n5.Display Array\n");
scanf("%d",&op);
switch(op)
{
case 1: input();
display();
break;
case 2: if(n==10)
printf("Array is full !!\n");
else if(n<=0)
printf("Array is empty !!\n");
else
{
printf("Enter element to insert and its position: ");
scanf("%d %d",&e,&ad);
if(ad>n)
printf("Address is not found !!\n");
else
{
insert(e,ad);
display();
}
}
break;
case 3: if(n<=0)
printf("Array is Empty !!\n");
else
{
printf("Enter position of element to delete: ");
scanf("%d",&ad);
if(ad>n)
printf("Address is not found !!\n");
else
{
delete(ad);
display();
}
}
break;
case 4: if(n<=0)
printf("Array is Empty !!\n");
else
{
search();
if(f!=0)
printf("Position of the element %d is at %d\n: ",e,(i+1));
else
printf("Element not found !!\n");
display();
}
break;
case 5: if(n<=0)
printf("Array is Empty !!\n");
else
{
display();
}
break;
default: printf("Enter valid input !\n");
}
printf("Do you want to continue ?('1' for yes / else for no): ");
scanf("%d",&ans);
}while(ans==1);
}
void input()
{
printf("Enter the number of elements(<=10): \n");
scanf("%d",&n);
if(n<=10 && n>=0)
{
printf("Enter the elements: \n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
}
else
printf("Enter integer between 0 to 10 !!");
}
void insert(int e,int ad)
{
for(i=n-1;i>=ad-1;i--)
{
a[i+1]=a[i];
}
a[ad-1]=e;
n+=1;
}
void delete(int ad)
{
for(i=ad-1;i<=n-2;i++)
{
a[i]=a[i+1];
}
n-=1;
}
int search()
{
printf("Enter element to search: ");
scanf("%d",&e);
for(i=0;i<n;i++)
{
if(a[i]==e)
{
f++;
goto retrn;
}
}
retrn:return(f);
}
void display()
{
printf("The Elements are: \n");
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
}