forked from Haresh1204/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert.c
More file actions
62 lines (56 loc) · 1.05 KB
/
insert.c
File metadata and controls
62 lines (56 loc) · 1.05 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
#include <stdlib.h>
void cal(int arr[], int size)
{
int pos, el;
printf("Enter new Element : ");
scanf("%d", &el);
printf("Enter The Position : ");
scanf("%d", &pos);
for (int i = size - 1; i >= pos - 1; i--)
{
arr[i + 1] = arr[i];
}
arr[pos - 1] = el;
}
void print(int arr[], int size)
{
printf("Array : \n");
for (int i = 0; i < size; i++)
{
printf("%d", arr[i]);
}
}
void new (int arr[], int size, int t)
{
cal(arr, size);
for (int i = 0; i < t-1; i++)
{
cal(arr, size);
}
print(arr, size);
}
int main(int argc, char const *argv[])
{
int size, t;
printf("Enter Array Size : ");
scanf("%d", &size);
int arr[size + 10];
printf("Enter Array Elements : ");
for (int i = 0; i < size; i++)
{
scanf("%d", &arr[i]);
}
printf("How many Elements : ");
scanf("%d", &t);
if (t == 1)
{
cal(arr, size);
print(arr, size);
}
else
{
new (arr, size, t);
}
return 0;
}