write a program to insert an element into an array

Answer Posted / renuka

#include<stdio.h>
#include<conio.h>
void insert(int b[],int n,int pos,int item);
void main()
{
int a[6]={10,20,30,40,50},p,c,item;
printf("enter item and position for insertion");
scanf("%d%d",&item,&p);
printf("array before insertion");
for(c=0;c<=4;c++)
{
printf("%d\n",a[c]);
}
insert(a,6,p,item);
printf("array after insertion");
for(c=0;c<=5;c++)
{
printf("%d\n",a[c]);
}
getch();
}
void(int b[],int n,int pos,int item)
{
int c;
c=n-1;
while(c>pos)
{
b[c]=b[c-1];
c--;
}
b[c]=item;
}

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a multimap c++?

772


Is c++ a float?

698


How is computer programming useful in real life?

670


Define a pointer to a data member of the type pointer to pointer?

661


What things would you remember while making an interface?

666






Write about the retrieval of n number of objects during the process of delete[]p?

661


Is dev c++ a good compiler?

600


What is a class definition?

704


Is c++ the hardest programming language?

735


What's c++ used for?

674


What is data type in c++?

648


What is setfill c++?

792


How c functions prevents rework and therefore saves the programers time as wel as length of the code ?

722


What is the best free c++ compiler for windows?

698


What is a far pointer? where we use it?

703