APC-S-010.c (958B)
1 /* 2 * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 12 Dec 2025 3 * Repo: https://github.com/notamitgamer/bsc 4 * License: MIT 5 */ 6 7 /* Write a program to input a new element at a specific position of an array. 8 a[] = {4, 5, 2, 10, 6, 9, 8}, newItem = 7, position = 3 9 */ 10 /* Author: Amit Dutta, Date: 18-11-2025 */ 11 12 #include <stdio.h> 13 14 int main() 15 { 16 int a[8] = {4, 5, 2, 10, 6, 9, 8}; 17 int i; 18 19 printf("Elemnts of the array: "); 20 for (i = 0; i <= 6; i++) 21 printf("%d ", a[i]); 22 23 printf("\nMethod 1: "); 24 for (i = 7; i >= 4; i--) 25 a[i] = a[i - 1]; 26 a[3] = 7; 27 for (i = 0; i <= 7; i++) 28 printf("%d ", a[i]); 29 30 // another method 31 printf("\nMethod 2: "); 32 int b[8] = {4, 5, 2, 10, 6, 9, 8}; 33 int temp1 = 7; 34 for (i = 3; i <= 7; i++) 35 { 36 int temp2 = b[i]; 37 b[i] = temp1; 38 temp1 = temp2; 39 } 40 for (i = 0; i <= 7; i++) 41 printf("%d ", b[i]); 42 43 return 0; 44 }