-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayinsertion.c
More file actions
35 lines (35 loc) · 814 Bytes
/
arrayinsertion.c
File metadata and controls
35 lines (35 loc) · 814 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
//array insertion program
#include<stdio.h>
void show(int arr[],int n){
for(int i=0;i<n;i++){
printf("%d ",arr[i]);
}
printf("\n");
}
int ins(int arr[],int ele,int index,int tindex){
if(index>=tindex){
printf("not sufficient space");
return -1;
}
for(int i=tindex;i>=index;i--){
arr[i]=arr[i-1];
}
arr[index]=ele;
return 0;
}
int main(){
int arr[15]={1,3,6,9,32};
int ele,index,tindex=15,size=5,a;
printf("enter the element to be inserted: ");
scanf("%d",&ele);
printf("enter the index at which you wanna insert the element");
scanf("%d",&index);
show(arr,size);
a=ins(arr,ele,index,tindex);
if(a==-1){
return 0;
}
size++;
show(arr,size);
return 0;
}