-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray
More file actions
79 lines (79 loc) · 1.97 KB
/
Copy patharray
File metadata and controls
79 lines (79 loc) · 1.97 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
72
73
74
75
76
77
78
79
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a[100];
int element,i,loc,size,n,j,choice;
printf("C Program to Insert and Delete an Element in an Array using switch case\n");
printf("1. Inserting an Element in an Array\n");
printf("2. Deleting an Element in an Array\n");
printf("Select your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter the size of an array\n");
scanf("%d",&size);
printf("Enter %d array elements\n",size);
for(i=0;i<size;i++)
{
scanf("%d",&a[i]);
}
printf("List before Insertion: ");
for(i=0;i<size;i++)
{
printf("%d ",a[i]);
}
printf("\nEnter an element to insert\n");
scanf("%d",&element);
printf("Enter a position to insert an element %d\n",element);
scanf("%d",&loc);
loc--;
for(i=size-1;i>=loc;i--)
{
a[i+1]=a[i];
}
a[loc]=element;
printf("List after Insertion: ");
for(i=0;i<size+1;i++)
{
printf("%d ",a[i]);
}
break;
case 2:
printf("Enter the size of an array\n");
scanf("%d",&size);
printf("Enter elements\n");
for(i=0;i<size;i++)
{
scanf("%d",&a[i]);
}
printf("List before deletion\n");
for(i=0;i<size;i++)
{
printf("%d ",a[i]);
}
printf("\nEnter an element to delete\n");
scanf("%d",&n);
for(i=0;i<size;i++)
{
if(a[i]==n)
{
for(j=i;j<(size-1);j++)
{
a[j]=a[j+1];
}
break;
}
}
printf("List after deletion\n");
for(i=0;i<(size-1);i++)
{
printf("%d ",a[i]);
}
break;
default:
printf("Wrong choice, Please try again later");
}
return 0;
}