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
Can recursive program be written in C++?
Explain what happens when a pointer is deleted twice?
What are the uses of pointers?
Is c++ used anymore?
Why do we use iterators?
Snake Game: This is normal snake game which you can find in most of the mobiles. You can develop it in Java, C/C++, C# or what ever language you know.
What do you mean by delegate? Can a user retain delegates?
Why null pointer is used?
Can I run c program in turbo c++?
What do you understand by zombie objects in c++?
Write some differences between an external iterator and an internal iterator? Describe the advantage of an external iterator.
How to declare a function pointer?
How the memory management in vectors are being done. What happens when the heap memory is full, and how do you handle it ?
Write a function to perform the substraction of two numbers. Eg: char N1="123", N2="478", N3=-355(N1-N2).
What is general form of pure virtual function? Explain?