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

Can recursive program be written in C++?

629


Explain what happens when a pointer is deleted twice?

733


What are the uses of pointers?

577


Is c++ used anymore?

585


Why do we use iterators?

616






Snake Game: This is normal snake game which you can find in most of the mobiles. You can develop it in Java, C/C++, C# or what ever language you know.

2436


What do you mean by delegate? Can a user retain delegates?

520


Why null pointer is used?

577


Can I run c program in turbo c++?

575


What do you understand by zombie objects in c++?

609


Write some differences between an external iterator and an internal iterator? Describe the advantage of an external iterator.

609


How to declare a function pointer?

575


How the memory management in vectors are being done. What happens when the heap memory is full, and how do you handle it ?

1830


Write a function to perform the substraction of two numbers. Eg: char N1="123", N2="478", N3=-355(N1-N2).

615


What is general form of pure virtual function? Explain?

507