top of page

A C Code to Insert into Array

  • Writer: Nelson John
    Nelson John
  • Nov 26, 2017
  • 1 min read

#include<stdio.h>

int main() {

int arr[20], element, num, i, pos;

printf("Enter no of elements :\n");

scanf("%d", &num);

for (i = 0; i < num; i++) {

scanf("%d", &arr[i]);

}

printf("Enter the position\n");

scanf("%d", &pos);

printf("Enter the element to be inserted :\n");

scanf("%d", &element);

//Create space at the specified position

for (i = num; i >= pos; i--) {

arr[i] = arr[i - 1];

}

num++;

arr[pos - 1] = element;

//Print out the result of insertion

for (i = 0; i < num; i++)

printf("%d ", arr[i]);

return (0);

}

Facebook: ayamnelrodinho1@gmail.com

Yahoo: talk2nelsonjohn2dat@yahoo.com

Whatsapp: +2349034595610

PLEASE KINDLY SHARE WITH FELLOW PROGRAMMERS AND ALSO SUBSCRIBE TO MY BLOG PAGE FOR MORE FEEDS.


 
 
 

Comentarios


bottom of page