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

Explain abstraction.

612


Explain method of creating object in C++ ?

587


How should a contructor handle a failure?

680


What is name hiding in c++?

605


Is turbo c++ free?

613






Why should we use null or zero in a program?

596


What is enum class in c++?

702


Which software is best for c++ programming?

570


Which format specifier is used for printing a pointer value?

569


Explain binary search.

570


What is class syntax c++?

590


What is buffering in c++?

580


List down the guideline that should be followed while using friend function.

644


Can a constructor return a value?

573


Do you know what is overriding?

615