Insert an Element in Array Program in C

Advertisements

Prev Tutorial Next Tutorial

Insert an Element in Array at Specific Position Program in C

Insert an Element in Array at Specific Position Program in C

#include<stdio.h>
#include<conio.h>

 void main()
  {
  int i,a[5],no,pos;
  clrscr();
  printf("Enter data in array: ");
  for(i=0;i<5;i++)
  {
  scanf("%d",&a[i]);
  }
  printf("\n\nStored Data in array: ");
  for(i=0;i<5;i++)
  {
  printf("  %d",a[i]);
  }
  printf("\n\nEnter possition number: ");
  scanf("%d",&pos);
  if(pos>5)
  {
  printf("\n\nThis is out of range");
  }
  else
  {
  printf("\n\nEnter new number = ");
  scanf("%d",&no);
  --pos;
  for(i=5;i>=pos;i--)
  {
  a[i+1]=a[i];
  }
  a[pos]=no;
  printf("\n\nNew data in array: ");
  for(i=0;i<6;i++)
  {
  printf("  %d",a[i]);
  }
  }
  getch();
  }

Output

insert an element in an array at specific position
Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements