APC-S-010.c ​
Metadata ​
- Author — Amit Dutta (amitdutta4255@gmail.com)
- Last updated — 12 Dec 2025
- License — MIT
Problem Statement ​
Problem Statement
Write a program to input a new element at a specific position of an array. a[] = {4, 5, 2, 10, 6, 9, 8}, newItem = 7, position = 3
Source Code ​
Printing the code
To print this file, open it on GitHub and click Raw before printing, or use the Download Raw button above and print directly from that page.
c
#include <stdio.h>
int main()
{
int a[8] = {4, 5, 2, 10, 6, 9, 8};
int i;
printf("Elemnts of the array: ");
for (i = 0; i <= 6; i++)
printf("%d ", a[i]);
printf("\nMethod 1: ");
for (i = 7; i >= 4; i--)
a[i] = a[i - 1];
a[3] = 7;
for (i = 0; i <= 7; i++)
printf("%d ", a[i]);
// another method
printf("\nMethod 2: ");
int b[8] = {4, 5, 2, 10, 6, 9, 8};
int temp1 = 7;
for (i = 3; i <= 7; i++)
{
int temp2 = b[i];
b[i] = temp1;
temp1 = temp2;
}
for (i = 0; i <= 7; i++)
printf("%d ", b[i]);
return 0;
}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
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