by Dinesh Thakur Category: Array
#include <stdio.h>

#include <conio.h>
int main()
{
     int i, n, num, pos, arr[10] ;
     clrscr();
     printf("\n Enter the number of elements in the array:" );
     scanf("%d", &n);
   for(i=0;i<n;i++)
   {
      printf("\n Arr[%d] = :",i);
      scanf("%d", &arr [i]);
   }
     printf("\n Enter the number to be inserted:");
     scanf("%d",&num);
     printf("\n Enter the position at which the number has to be added:");
     scanf("%d", &pos);
   for(i=n;i>=pos;i--)
   {
     arr[i+1] = arr[i];
   }
     arr[pos] = num;
     n++;
     printf("\n The array after insertion  is: ",&num);
  for(i=0;i<n;i++)
  {
     printf (" \n Arr [%d]=%d",i,arr[i]);
  }
    getch();
    return 0;
}

insert a number at a given location in an array



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles