bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_1 / tuition-c / APC-S-010.c

APC-S-010.c (822B)


      1 /* Write a program to input a new element at a specific position of an array.
      2     a[] = {4, 5, 2, 10, 6, 9, 8}, newItem = 7, position = 3
      3 */
      4 /* Author: Amit Dutta, Date: 18-11-2025 */
      5 
      6 #include <stdio.h>
      7 
      8 int main()
      9 {
     10     int a[8] = {4, 5, 2, 10, 6, 9, 8};
     11     int i;
     12 
     13     printf("Elemnts of the array:  ");
     14     for (i = 0; i <= 6; i++)
     15         printf("%d  ", a[i]);
     16 
     17     printf("\nMethod 1:  ");
     18     for (i = 7; i >= 4; i--)
     19         a[i] = a[i - 1];
     20     a[3] = 7;
     21     for (i = 0; i <= 7; i++)
     22         printf("%d  ", a[i]);
     23 
     24     // another method
     25     printf("\nMethod 2:  ");
     26     int b[8] = {4, 5, 2, 10, 6, 9, 8};
     27     int temp1 = 7;
     28     for (i = 3; i <= 7; i++)
     29     {
     30         int temp2 = b[i];
     31         b[i] = temp1;
     32         temp1 = temp2;
     33     }
     34     for (i = 0; i <= 7; i++)
     35         printf("%d  ", b[i]);
     36 
     37     return 0;
     38 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror