-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray insert.c
58 lines (45 loc) · 914 Bytes
/
array insert.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
//INSERTION AT END
/*#include<stdio.h>
int main()
{
int arr[10]={10,11,3,6,15};
int len=5;
int i,n;
printf("Original Array :");
for(i=0;i<len;i++){
printf("%d ",arr[i]);
}
printf("\nEnter Number to be inserted at end :");
scanf("%d",&n);
arr[len]=n;
printf("\nAfter Insertion :");
for(i=0;i<len+1;i++){
printf("%d ",arr[i]);
}
return 0;
}
*/
#include <stdio.h>
int main()
{
int arr[10],i,pos,n,x;
printf("Enter numbers of elemnets for the array :");
scanf("%d",&n);
printf("Enter %d numbers:\n",n);
for(i=0;i<n;i++){
scanf("%d",&arr[i]);
}
printf("Enter location to insert number :");
scanf("%d",&pos);
printf("Enter x to insert :");
scanf("%d",&x);
for(i=n-1;i>=pos-1;i--){
arr[i+1]=arr[i];
}
arr[pos-1]=x;
printf("Final Array is:\n");
for(i=0;i<=n;i++){
printf("%d ",arr[i]);
}
return 0;
}