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
Is facebook written in c++?
What is constructor c++?
Explain the static member function.
Is turbo c++ free?
If a function doesn’t return a value, how do you declare the function?
What is the best c++ compiler?
Write about the use of the virtual destructor?
What is the best free c++ compiler for windows?
What is c++ hiding?
What is the benefit of learning c++?
How the keyword struct is different from the keyword class in c++?
What does #define mean in c++?
What does I ++ mean in c++?
What is the best c++ ide?
Write a program to show polymorphism in C++?