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 the best way to take screenshots of a window with c++ in windows?
Is it possible to write a c++ template to check for a function's existence?
What is c++ runtime?
What is #include cstdlib in c++?
Explain static and dynamic memory allocation with an example each.
What is difference between malloc()/free() and new/delete?
Of the numbers 12 23 9 28 which would be at the top of a properly implemented maxheap a) 28 b) 9 c) Any of them could be
How do you compile the source code with your compiler?
Why is that unsafe to deal locate the memory using free( ) if it has been allocated using new?
Should I learn c++ c?
What is flush programming?
What is a pointer how and when is it used?
Explain the differences between list x; & list x();.
What will strcmp("Astring", "Astring"); return a) A positive value b) A negative value c) Zero
What is abstraction c++?