-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdd Delete Array Elements 1
More file actions
60 lines (54 loc) · 1.07 KB
/
Add Delete Array Elements 1
File metadata and controls
60 lines (54 loc) · 1.07 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
#include <stdio.h>
void add(int [],int *, int, int);
void display(int [],int);
void delete(int [],int *, int, int);
int main()
{
int arr[20], n, i, x, in;
printf("Enter the total number of elements: ");
scanf("%d", &n);
printf("Enter the %d elements: ", n);
for(i=0; i<n; i++)
scanf("%d ", &arr[i]);
printf("Enter the number to be added and the position: ");
scanf("%d %d", &x, & in);
add(arr, &n, x, in);
display(arr, n);
delete(arr, &n, x, in);
display(arr, n);
return 0;
}
void add(int a[],int *p, int x, int in)
{
int n=*p, temp, t;
for(int i=0; i<=n; i++)
{
if(i=in)
{
temp=a[i];
a[i]=x;
}
if(i>in)
{
t= a[i];
a[i]=temp;
temp=t;
}
}
}
void delete(int a[],int *p, int x, int in)
{
int n=*p;
for(int i=0; i<=n; i++)
{
if(i>in)
{
a[i]=a[i+1];
}
}
}
void display(int a[],int n)
{
for(int i=0; i<n; i++)
printf("%d ", a[i]);
}