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
If we want that any wildcard characters in the command line arguments should be appropriately expanded, are we required to make any special provision? If yes, which?
Explain the register storage classes in c++.
what is upcasting in C++?
How do you flush a buffer in c++?
Write a program that takes a 5 digit number and calculates 2 power that number and prints it.
What is the basic structure of c++ program?
Is python written in c or c++?
What is the best free c++ compiler for windows?
How do you clear a map in c++?
What are vtable and vptr?
What are friend classes? What are advantages of using friend classes?
What is the main use of c++?
Can recursive program be written in C++?
What is a static element?
Difference between declaration and definition of a variable.