-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patharray_deletion.c
46 lines (42 loc) · 919 Bytes
/
array_deletion.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
// [to delete an element in an array]
#include <stdio.h>
int deletepos(int[], int);
void display(int[],int);
int main()
{
int a[10],i,n;
printf("Enter no. of elements in an array:\n");
scanf("%d",&n);
printf("Enter elements of an array:\n");
for (i=0;i<n;i++)
scanf("%d",&a[i]);
if(deletepos(a,n))
n = n-1;
display(a,n);
}
int deletepos(int b[], int m)
{
int p,i;
printf("Enter position which you want to delete:\n");
scanf("%d",&p);
if (p==0)
printf("Error: Entered position smaller than initial one.\n");
else if (p>m)
{
printf("Error: Entered position greater than size of array.\n");
}
else
{
for (i=p-1;i<(m-1);i++)
b[i]=b[i+1];
return 1;
}
return 0;
}
void display(int b[],int n)
{
int i;
printf("New array is:\n");
for (i=0;i<n;i++)
printf("%d\n",b[i]);
}