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
What is buffer and example?
What is dynamic and static typing?
List the types of polymorphism in c++?
Why do we use classes in programming?
Is map ordered c++?
Describe friend function & its advantages.
What is a dynamic binding in c++?
Explain friend class?
What are the advantages of using pointers in a program?
Is c++ platform dependent?
What is a node class in c++?
Can we change the basic meaning of an operator in c++?
What do you mean by ‘void’ return type?
What is a rooted hierarchy?
Can notepad ++ run c++?