-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdd_an_element_at_front_of_array.c
More file actions
46 lines (40 loc) · 1021 Bytes
/
Add_an_element_at_front_of_array.c
File metadata and controls
46 lines (40 loc) · 1021 Bytes
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
// Add an element at front in array
// for insert an element in array we must create an array which is not full i.e. number of elements must be less than the size of array
#include <stdio.h>
int main()
{
int arr[50], n, i, num, j, pos = 4;
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("The array is\n");
for (i = 0; i < n; i++)
{
printf("%d ", arr[i]);
}
printf("\nEnter the value which you want to insert in array\n");
scanf("%d", &num);
for (j = n; j > 0; j--)
{
arr[j] = arr[j - 1];
}
arr[j] = num;
n++;
printf("After add %d element in array\n", num);
for (i = 0; i < n; i++)
{
printf("%d ", arr[i]);
}
}
return 0;
}