-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathday036.c
35 lines (29 loc) · 1.06 KB
/
day036.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
#include <stdio.h>
int main(void) {
int current_array[50], insert_array[50], array_size, insert_element, insert_index, temp;
printf("Enter the size of the array\n");
scanf("%d", &array_size);
printf("Input %d elements\n", array_size);
//get and copy the value to another array
for(int i=0; i<array_size; i++){
scanf("%d", ¤t_array[i]);
insert_array[i] = current_array[i];
}
//get element and index to insert
printf("Enter the value to be inserted\n");
scanf("%d", &insert_element);
printf("Enter the index, after the index, value will be inserted\n");
scanf("%d", &insert_index);
//insertion performed here !!!
for(int i=array_size-1; i>insert_index; i--)
insert_array[i+1] = insert_array[i];
insert_array[insert_index+1] = insert_element;
//result printing...
printf("The current list of the array\n");
for(int i=0; i<array_size; i++)
printf("%d ", current_array[i]);
printf("\nAfter Insert the element the new list is\n");
for(int i=0; i<array_size+1; i++)
printf("%d ", insert_array[i]);
return 0;
}