forked from Mdmanwar01/Array-in-c-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC_language_Array_implementation.c
More file actions
55 lines (47 loc) · 1.47 KB
/
Copy pathC_language_Array_implementation.c
File metadata and controls
55 lines (47 loc) · 1.47 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//Array Implementation in c , with functionalities such Display the array, Insert into the Array and Delete from the Array.
#include<stdio.h>
#include<conio.h>
void DISPLAY(int *arr,int n) //Display function to Display the current elemnets in the Array.
{
for(int i=0;i<n;i++)
printf("%d ",arr[i]);
printf("\n");
}
void INSERT(int *arr,int n) //Insert function to insert an element anywhere in the array.
{
int item,index;
printf("Random Insertion \n");
printf("Enter the item to Insert:-");
scanf("%d",&item);
printf("Enter the Index number to insert(between 0-%d)",n-1);
scanf("%d",&index);
for(int i=n-1;i>=index;i--)
{
arr[i+1]=arr[i];
}
arr[index]=item;
}
void DELETE(int *arr,int n) //Delete function to Delete any element from the array.
{
int index;
printf("Enter the index position to delete(between 0-%d):-",n-1);
scanf("%d",&index);
for(int i=index;i<n;i++)
arr[i]=arr[i+1];
}
int main()
{
int n;
printf("Enter the size of the array:-");
scanf("%d",&n);
int arr[n+1];
for(int i=0;i<n;i++) //initializing the array
{
printf("Enter %d Element of the array:-",i+1);
scanf("%d",&arr[i]);
}
INSERT(arr,n); //calling INSERT function
DISPLAY(arr,n); //calling DISPLAY function
DELETE(arr,n); //calling DELETE function
DISPLAY(arr,n); //calling DISPLAY function
}