-
Notifications
You must be signed in to change notification settings - Fork 4
/
arraydeleteevenelem.c
73 lines (70 loc) · 1.8 KB
/
arraydeleteevenelem.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
/*Implement a menu driven program to create an
array with the following options a) delete a given element b) delete even
numbers.*/
#include <stdio.h>
void main()
{
int i, j, n, c, p;
printf("Enter the size of array: ");
scanf("%d", &n);
int a[n];
printf("\nEnter the array: ");
for (i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
printf("\nEntered array is: ");
for (i = 0; i < n; i++)
{
printf("%d\t", a[i]);
}
do
{
printf("\n\nEnter the option you want to perform:\n1.delete a given element\n2.delete even numbers\n3.exit\n");
scanf("%d", &c);
switch (c)
{
case 1:
printf("\nEnter the position of the Element that you want to delete: ");
scanf("%d", &p);
if (p >= n)
{
printf("Cannot Delete\n");
}
else
{
for (i = p; i < (n - 1); i++)
{
a[i] = a[i + 1];
}
}
printf("\nNew array : ");
for (i = 0; i < n - 1; i++)
{
printf("%d\t", a[i]);
}
break;
case 2:
printf("New Array is\n");
for (i = 0; i < n; i++)
{
if (a[i] % 2 == 0)
{
for (j = i; j < n - 1; j++)
{
a[j] = a[j + 1];
}
n--;
i--;
}
else
{
printf("%d\t", a[i]);
}
}
break;
case 3:
break;
}
} while (c != 3);
}