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
Explain queue. How it can be implemented?
What is singleton class in c++?
Is c better than c++?
Can a program run without main?
How do you compile the source code with your compiler?
Do vectors start at 0 c++?
What are references in c++?
What is the full form of ios?
What are the advantages of using a pointer?
What are the two types of comments?
what does the following statement mean? int (*a)[4]
How to declaring variables in c++?
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?
Explain the pure virtual functions?
What is the role of static keyword for a class member variable?