-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDelete_an_element_at_fornt_from_array.c
More file actions
43 lines (37 loc) · 1.06 KB
/
Copy pathDelete_an_element_at_fornt_from_array.c
File metadata and controls
43 lines (37 loc) · 1.06 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
// Delete an element from front of the array
#include<stdio.h>
int main()
{
int arr[50], n, i, j, num;
printf("Enter size of array\n");
scanf("%d", &n);
if (n > 50)
{
printf("Overflow Condition.\n");
}
else
{
printf("Enter array elements\n");
for (i = 0; i < n; i++)
{
scanf("%d", &arr[i]);
}
printf("Elements of the array is\n");
for (i = 0; i < n; i++)
{
printf("%d ", arr[i]);
}
num = arr[0];
for (j = 0; j < n - 1; j++) // in this line j goes to n-1, n=10, when inserting elements then i goes to less than n, i.e. n=9, so at deletion if j goes to less than 9 then when j = 9 then arr[9] = arr[10], and after left shifiting I decrement the size - 1, so arr[10] is garbage value.
{
arr[j] = arr[j + 1];
}
printf("\nAfter delete the %d at front from array\n", num);
n--;
for (j = 0; j < n; j++)
{
printf("%d ", arr[j]);
}
}
return 0;
}