Write a program that accepts an array of numbers, and two
numbers (an element and a
position in the array) and inserts the given element into
nth position of the array.

Answer Posted / surabhi

void main()
{
int x[6],item,pos,i,n;
printf("\n enter no of elements to be inserted:");
scanf("\n %d",&n);
for(i=0;i<n;i++)
{
printf("\n enter elements:");
scanf("%d",&x[i]);
}
printf("\n enter item to be inserted:");
scanf("%d",&item);
printf("\n enter position:");
scanf("%d",&pos);
for(i=n;i<=pos-1;i--)
{
x[i+1]=x[i];
}
x[pos-1]=item;
printf("\n elements after insertion:");
for(i=0;i<=n;i++)
{
printf("\n %d",x[i]);
}
getch();
}

Is This Answer Correct ?    3 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Observations between vb.net and vc#.net?

656


Why do we use byref keyword in vb.net?

695


Explain the differences between vb.net and c#, related to oops concepts?

598


What are the advantages of migrating to vb.net?

641


what is interface and when it is used?

1904






What is the difference between custom control and user control?

631


What is the class that allows an element to be accessed using unique key?

625


source code for how to login a vb.net application ?

666


What are the objects in asp.net?

631


What is the difference between datagrid and gridview?

593


What would you do to remove microsoft visual basic name space?

582


What is meant by jagged arrays?

652


What is redim keyword and its use?

675


How do you define a read only property in a class module?

597


What is internal keyword in .net framework?

710