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 queue. How it can be implemented?

670


What is singleton class in c++?

589


Is c better than c++?

611


Can a program run without main?

622


How do you compile the source code with your compiler?

613






Do vectors start at 0 c++?

531


What are references in c++?

652


What is the full form of ios?

551


What are the advantages of using a pointer?

602


What are the two types of comments?

570


what does the following statement mean? int (*a)[4]

617


How to declaring variables in c++?

657


Am studying basic c++ programming, have been given the following assignment. Design a linear program to calculate the maximum stress a material can withstand given a force and a diameter of a circle. To find the required area pi should be defined. Have most of the program sorted out but am at a loss as to how to show the calculations required. Can anyone help?

1734


Explain the pure virtual functions?

634


What is the role of static keyword for a class member variable?

627