-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsarray.c
More file actions
40 lines (37 loc) · 1.17 KB
/
Copy pathinsarray.c
File metadata and controls
40 lines (37 loc) · 1.17 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
/*-------------------------------------------------------------------------------------------------------------------------------
insarray.c
Program to insert a particular number in a particular position in an array
DIVYA RAJ K
22-09-2018
---------------------------------------------------------------------------------------------------------------------------------*/
#include<stdio.h>
#include<math.h>
main()
{
int X[30],N,i,j,Temp,Ele,Loc;
system("clear");
printf("Program to insert a particular number in a particular position in an array\n\n");
printf("Enter the number of elements: ");
scanf("%d",&N);
printf("Enter %d numbers:\n",N);
for(i=1;i<=N;i++){
scanf("%d",&X[i]);
}
printf("\nEnter the position at which you have to enter an element: ");
scanf("%d",&Loc);
if(Loc<=(N+1)){
printf("\nEnter the element that you have to insert to the position %d: ",Loc);
scanf("%d",&Ele);
for(i=N+1;i>Loc;i--){
X[i]=X[i-1];
}
X[Loc]=Ele;
printf("\nThe elements of the array after inserting element %d to location %d is\n",Ele,Loc);
for(i=1;i<=(N+1);i++){
printf("%d\n",X[i]);
}
}
else{
printf("\nSorry! You cant insert an element to that location");
}
}