-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9.c
44 lines (38 loc) · 1.01 KB
/
9.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
//WAP to Insert an element at a specific position in an array and rest of the array vales must be shifted to next array positions.
#include <stdio.h>
#define MAX_SIZE 100
int main()
{
int arr[MAX_SIZE];
int i, size, num, pos;
printf("\nEnter Size of the Array: ");
scanf("%d", &size);
printf("Enter Elements in Array:-\n");
for(i=0; i<size; i++)
{
scanf("%d", &arr[i]);
}
printf("\nEnter Element to Insert: ");
scanf("%d", &num);
printf("Enter the Element Position: ");
scanf("%d", &pos);
if(pos > size+1 || pos <= 0)
{
printf("Invalid Position! Please Enter Position Between 1 to %d", size);
}
else
{
for(i=size; i>=pos; i--)
{
arr[i] = arr[i-1];
}
arr[pos-1] = num;
size++;
printf("\nArray Elements After Insertion: ");
for(i=0; i<size; i++)
{
printf("%d\t", arr[i]);
}
}
return 0;
}