Friday 21 October 2016

DATA STRUCTURE (D S)-INSERT AN ELEMENT IN A LINEAR ARRAY

CODINGCLASSES|LEARNTOPROGRAM

Example of    INSERT AN ELEMENT IN A LINEAR ARRAY


#include<iostream.h>
#incllude<conio.h>
void main()
{
int b[100],n,loc,temp,item;//variable with dattypes
cout<<"Enter the size of an array ";
cin>>n;
cout<<"Enter the elemnet of an array ";
for(int i=0; i<=n; i++)
{
cin>>b[i];
}
cout<<"Enter the position to insert the number ";
cin>>loc;
if(loc>n)
{
cout<<" this the out of range exit";
}
else
{
cout<<" Enter the new items or no";
cin>>item;
for(i=n; i>=loc-1; i--)
{
a[i+1] =a[i];
}
A[loc-1] =item;
cout<<" New element inserted in array";
for(i=0; i<n+1; i++)
{
cout<<a[i];
}
}
getch();
}


o/p-Enter the size 5
Enter the elements
2
3
4
5
6
7
Enter the position no = 2
Enter the new item or no=9
New element inserted in array
2
3
9
4
5
6
7

IN this example no any compile time and no any run time error it is already checked in turbo c++ ide If you want to ask any question plz comment below

KEEP VISITING FOR LATEST UPDATES
TILL THEN KEEP CODING!!

No comments:

Post a Comment