-
Notifications
You must be signed in to change notification settings - Fork 1
/
q3.c
57 lines (52 loc) · 948 Bytes
/
q3.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
/***********************************************************
Program to insert an element at a given index of an array
Author: leonatwork(Noel Aby Das)
**********************************************************/
#include<stdio.h>
void main()
{
int a[25],n,i,p,q;
label:
printf("enter the size of array : ");
scanf("%d",&n);
if(n<1)
{
printf("Invalid size\nEnter again\n");
goto label;
}
else if(n>25)
{
printf("Array size too large\nenter smaller value\n");
goto label;
}
printf("enter %d elements : \n",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("enter the number you want to insert : ");
scanf("%d",&q);
pslabel:
printf("enter the postion of insertion : ");
scanf("%d",&p);
if(p>n+1||p<0)
{
printf("Invalid position\nEnter again\n");
goto pslabel;
}
if(n==25)
{
printf("overflow\n");
}
else{
for(i=n;i>=p;i--)
{
a[i]=a[i-1];
}
a[p-1]=q;
printf("the new array is : ");
for(i=0;i<n+1;i++)
{
printf("%d ",a[i]);
}
printf("\n");
}
}