-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInsertInArray.c
More file actions
42 lines (33 loc) · 869 Bytes
/
InsertInArray.c
File metadata and controls
42 lines (33 loc) · 869 Bytes
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
#include<stdio.h>
int main()
{
int array [50],position,i,n,value;
printf( "Enter number of elements in array : " ) ;
scanf("%d",&n);
while(n>50||n<0)
{
printf("\nERROR... The range for elements is 1 to 50");
printf("\nEnter the total number of elements again : ");
scanf("%d",&n);
}
printf("\n");
for(i=0;i<n;i++)
{
printf("Enter the %d element : ",i+1);
scanf("%d",&array[i]);
}
printf("\nEnter the location where you wish to insert an element :" );
scanf("%d",&position) ;
printf("\nEnter the value to insert : " );
scanf("%d",&value);
for(i=n-1;i>=position-1;i--)
array[i+1]=array[i];
array[position-1]=value;
printf("\nResultant array is : \n\n") ;
for(i=0;i<=n;i++)
{
printf("The %d element is ",i+1);
printf("%d\n",array[i]);
}
return 0;
}