-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathelement-instertion-array.c
83 lines (70 loc) · 4.32 KB
/
element-instertion-array.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
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
80
81
82
83
# include<stdio.h>
void insert(int *);
void main()
{
int arr[10];
int *ptr;
ptr = &arr[0];
printf("Value insertion in Array\n\n");
for (int i = 0; i < 10; i++)
{
printf("> Enter: ");
scanf("%d", ptr+i);
}
printf("\n");
printf("> Values entered: ");
for (int i = 0; i < 10; i++)
{
if (i != 9)
printf("%d , ", *(ptr+i));
else
printf("%d", *(ptr+i));
}
insert(ptr);
}
void insert(int *arr)
{
int position;
int *ptr;
int numb;
ptr = &arr[0];
printf("\n\n");
printf("> To insert value, enter position: ");
scanf("%d", &position);
printf("\n");
printf("Enter value to insert: ");
scanf("%d", &numb);
printf("\n");
for (int i = 9; i >= position-1; i--)
{
arr[i+1] = arr[i];
}
arr[position-1] = numb;
for (int i = 0; i < 11; i++)
{
if (i != 10)
printf("%d , ", arr[i]);
else
printf("%d", arr[i]);
}
printf("\n");
}
/* Output
Value insertion in Array
> Enter: 12
> Enter: 45
> Enter: 65
> Enter: 87
> Enter: 98
> Enter: 21
> Enter: 17
> Enter: 19
> Enter: 36
> Enter: 59
> Values entered: 12 , 45 , 65 , 87 , 98 , 21 , 17 , 19 , 36 , 59
> To insert value, enter position: 6
Enter value to insert: 100
12 , 45 , 65 , 87 , 98 , 100 , 21 , 17 , 19 , 36 , 59
...Program finished with exit code 10
Press ENTER to exit console.
*/