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 are shallow and deep copies?
To which numbering system can the binary number 1101100100111100 be easily converted to?
What do nonglobal variables default to a) auto b) register c) static
How many different levels of pointers are there?
Describe linked list using C++ with an example.
write a programme to get a character and thier ASCII value
What is a dll entry point?
What is an object in c++?
Differentiate between a pointer and a reference with respect to c++.
Write a program using shift_half( ) function to shift the elements of first half array to second half and vice versa.
Which function should be used to free the memory allocated by calloc()?
What is implicit pointer in c++?
What new()is different from malloc()?
What is a down cast?
What are stacks? Give an example where they are useful.