-
Notifications
You must be signed in to change notification settings - Fork 0
/
ds_2.c
35 lines (34 loc) · 817 Bytes
/
ds_2.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
#include <stdio.h>
int main()
{
int a[10];
int n,i,x,size;
printf("Size of array is=\n"); //size of array
scanf("%d",&size);
printf("Enter %d array elements=\n",size);
for(i=0;i<size;i++) //entering elements inside array
{
scanf("%d",&a[i]);
}
printf("Current array= "); //printing array
for(i=0;i<size;i++)
{
printf("%d ",a[i]);
}
printf("\nEnter an element to insert=\n"); //element to insert
scanf("%d",&n);
printf("Enter position for element %d=\n",n); //position of new element
scanf("%d",&x);
x=x-1;
for(i=size-1;i>=x;i--)
{
a[i+1]=a[i];
}
a[x]=n;
printf("\nNew array= ");
for(i=0;i<size+1;i++) //printing new array
{
printf("%d ",a[i]);
}
return 0;
}