-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram1
More file actions
71 lines (68 loc) · 2.08 KB
/
program1
File metadata and controls
71 lines (68 loc) · 2.08 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
#include<stdio.h>
#include<stdlib.h>
main()
{
int *arr;
int n, i, choice, pos, x, key, found = 0;
printf("Enter the number of elements in the array:");
scanf("%d", &n);
arr = (int *)malloc(n * sizeof(int));
printf("Enter the elements");
for(i = 0; i < n; i++)
scanf("%d", (arr + i));
printf("The elements of the array are :\n");
for(i = 0; i < n; i++)
{
printf("*(arr+%d)=%d\n", i, *(arr + i));
}
while(1)
{
printf("\n1-> INSERT 2-> DELETE 3-> SEARCH 4->EXIT\n");
printf("Give your choice:");
scanf("%d", &choice);
switch(choice)
{
case 1:
printf("Enter the element to be inserted:");
scanf("%d", &x);
printf("Enter the position to be inserted:");
scanf("%d", &pos);
n++;
for(i = n - 1; i >= pos; i--)
*(arr + i) = *(arr + i - 1);
*(arr + pos - 1) = x;
printf("After insertion the elements of the array are :\n");
for(i = 0; i < n; i++)
{
printf("*(arr+%d)=%d\n", i, *(arr + i));
}
break;
case 2:
printf("Enter the position of the element to be deleted:");
scanf("%d", &pos);
for(i = pos; i <= n - 1; i++)
*(arr + i - 1) = *(arr + i);
n--;
printf("After deletion the elements of the array are :\n");
for(i = 0; i < n; i++)
{
printf("*(arr+%d)=%d\n", i, *(arr + i));
}
break;
case 3:
found = 0;
printf("Enter the element to be searched:");
scanf("%d", &key);
for(i = 0; i <= n; i++)
if(*(arr + i) == key)
{
found = 1;
printf("\n Search key %d is found at position %d", i + 1);
}
if(found == 0)
printf("Search key %d is not found", key);
break;
case 4: exit(1);
}
}
}