-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray element delete.c
More file actions
62 lines (60 loc) · 1.63 KB
/
Copy pathArray element delete.c
File metadata and controls
62 lines (60 loc) · 1.63 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
#include <stdio.h>
int main()
{
printf("Enter 1 do delete array using array position ");
printf("\nEnter 2 do delete array using array element ");
int ch;
scanf("%d",&ch);
printf("\nEnter the size of the array ");
int size;
scanf("%d",&size);
int arr[size];
printf("\nEnter the elements of the array ");
for(int i=0;i<size;i++)
scanf("%d",&arr[i]);
switch(ch)
{
case 1:
printf("\nEnter the position you want to delete ");
int pos;
scanf("%d",&pos);
pos=pos-1;
printf("\n The array before deletion is : ");
for(int i=0;i<size;i++)
printf("%d ",arr[i]);
for(int i=pos;i<size;i++)
arr[i]=arr[i+1];
printf("\n The array after deletion is : ");
for(int i=0;i<size-1;i++)
printf("%d ",arr[i]);
break;
case 2:
printf("\nEnter the element you want to delete ");
int ele,f=0,pos1;
scanf("%d",&ele);
for(int i=0;i<size;i++)
if(ele==arr[i])
{
f=1;
pos1=i;
break;
}
if(f==1)
{
printf("\nThe array before deletion is : ");
for(int i=0;i<size;i++)
printf("%d ",arr[i]);
for(int i=pos1;i<size;i++)
arr[i]=arr[i+1];
printf("\nThe array after deletion is : ");
for(int i=0;i<size-1;i++)
printf("%d ",arr[i]);
}
else
printf("Element not present in the array");
break;
default :
printf("Entered choice doesnot match the condition");
}
return 0;
}