C Program to Insert an item into an Array

#include <stdio.h>
int main()
{
  int Array[10], Position, i, Number, Value;
  printf(“\n Number of elements in an array\n”);
  scanf(“%d”, &Number);
  printf(“\n Enter %d elements of an Array \n”, Number);
  for (i = 0; i < Number; i++)
   {
     scanf(“%d”, &Array[i]);
   }
  printf(“\n location to insert\n”);
  scanf(“%d”, &Position);
  printf(“\nvalue to insert\n”);
  scanf(“%d”, &Value);
  for (i = Number – 1; i >= Position – 1; i–)
   {
     Array[i+1] = Array[i];
   }
  Array[Position-1] = Value;
  Number++;
 printf(“\n Final Array after Inserting an  Elemnt is:\n”);
 for (i = 0; i <Number; i++)
  {
  printf(“%d\t”, Array[i]);
  }
 return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>