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
Are php strings immutable?
What is flush c++?
Why are arrays usually processed with for loop?
How much is c++ certification?
When we use Abstract Class and when we use Interface?where we will implement in real time?
Write about the role of c++ in the tradeoff of safety vs. Usability?
Can recursive program be written in C++?
What do you mean by stack unwinding in c++?
How to access a variable of the structure?
What is abstraction with real time example?
Ask to write virtual base class code?
What are the different types of polymorphism in c++?
What are multiple inheritances (virtual inheritance)? What are its advantages and disadvantages?
Give example of a pure virtual function in c++?
What are compilers in c++?