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
What is a buffer c++?
What is purpose of new operator?
What are single and multiple inheritances in c++?
Which is the best c++ software?
Explain what are mutator methods in c++?
What is the difference between the functions memmove() and memcpy()?
How to tokenize a string in c++?
Specify different types of decision control statements?
What is a multiset c++?
Arrange Doubly linked list in the ascending order of its integral value and replace integer 5 with 7?
write a function signature with various number of parameters.
Define anonymous class.
What happens when the extern "c" char func (char*,waste) executes?
Explain the pure virtual functions?
Is c++ used anymore?