write a program to insert an element into an array

Answer Posted / jyoti sur

#include<stdio.h>
#include<conio.h>
void main()
{
int pos,k,n,a[30];
int i;
clrscr();
printf("enter no.of element in array\n");
scanf("%d",&n);
printf("enter the elements\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("your array is:\n");
for(i=0;i<n;i++)
{
printf("%6d",a[i]);
}
printf("\nenter the no.for insertion\n");
scanf("%d",&k);
printf("\n\nenter the position");
scanf("%d",&pos);
--pos;

if(pos<n)
{
for(i=n;i>=pos;i--)

a[i+1]=a[i];
a[pos]=k;
n++;

}
else
printf("\n outside the array");
printf("the new array is:");
for(i=0;i<n;i++)
{
printf("%6d",a[i]);
}
}

Is This Answer Correct ?    91 Yes 20 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Are php strings immutable?

556


What is flush c++?

533


Why are arrays usually processed with for loop?

766


How much is c++ certification?

581


When we use Abstract Class and when we use Interface?where we will implement in real time?

1664






Write about the role of c++ in the tradeoff of safety vs. Usability?

589


Can recursive program be written in C++?

627


What do you mean by stack unwinding in c++?

724


How to access a variable of the structure?

581


What is abstraction with real time example?

612


Ask to write virtual base class code?

2147


What are the different types of polymorphism in c++?

583


What are multiple inheritances (virtual inheritance)? What are its advantages and disadvantages?

561


Give example of a pure virtual function in c++?

581


What are compilers in c++?

601