• Program to insert an element in an array at a given position
  • C program to insert an element in an array without using function



Program #1: Write a c program to insert an element in array without using function


  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6.   int insarray[100], pos, c, n, value;
  7.  
  8.   printf("Enter number of elements of array\n");
  9.    scanf("%d", &n);
  10.  
  11.    printf("Enter all %d elements\n", n);
  12.  
  13.    for (c = 0; c < n; c++)
  14.       scanf("%d", &insarray[c]);
  15.  
  16.    printf("Enter the specific position where you wish to insert an element in array\n");
  17.    scanf("%d", &pos);
  18.  
  19.    printf("Enter the value to insert\n");
  20.    scanf("%d", &value);
  21.  
  22.    for (c = n - 1; c >= pos - 1; c--)
  23.       insarray[c+1] = insarray[c];
  24.  
  25.    insarray[pos-1] = value;
  26.  
  27.    printf("Resultant array is\n");
  28.  
  29.    for (c = 0; c <= n; c++)
  30.       printf("%d\n", insarray[c]);
  31.  
  32. getch();
  33. }
Output:

insert element in array c

Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu