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
How to give an alternate name to a namespace?
What is an incomplete type in c++?
What is the syntax for a for loop?
When do we use copy constructors?
How to allocate memory dynamically for a reference?
describe private access specifiers?
When there is a global variable and local variable with the same name, how will you access the global variable?
How to get the current position of the file pointer?
What is ios flag in c++?
What is low level language in simple words?
Why namespace is used in c++?
What is microsoft c++ redistributable 2013?
Explain stack unwinding.
What do you understand by pure virtual function? Write about its use?
Explain the isa and hasa class relationships.