write a program to insert an element into an array
Answer Posted / ranjit kumar
#include<stdio.h>
#include<conio.h>
void main()
{
int a[11],i,j,k,ch,sh,e;
clrscr();
printf("enter array elements:");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
printf("enter choice\n1.in between insertion\n2.insertion in the beginning\n3.insertion at the end");
scanf("%d",&ch);
switch(ch)
{case1:
printf("enter the element:");
scanf("%d",&e);
printf("enter the element after which the number has to be inserted:");
scanf("%d",&sh);
for(i=0;i<10;i++)
{
if(a[i]==sh)//finding the element
break;
}
for(k=9;k>i;k--)
a[k+1]=a[k];//shifting the element
a[i+1]=e;
break;
case2:
printf("enter the element:");
scanf("%d",&e);
for(k=9;k>=0;k--)
a[k+1]=a[k];
a[0]=e;
break;
case3:
printf("enter the element:");
scanf("%d",&e);
a[10]=e;
}
printf("\n");
for(i=0;i<10;i++)//display the result
printf("%d",a[i]);
getch();
}
Is This Answer Correct ? | 1 Yes | 2 No |
Post New Answer View All Answers
Can you pass an array to a function in c++?
How should a contructor handle a failure?
What is the type of 'this' pointer?
What is the latest c++ standard?
Which bitwise operator is used to check whether a particular bit is on or off?
Should the this pointer can be used in the constructor?
What are the differences between new and malloc?
What are the comments in c++?
Are c and c++ similar?
How to declaring variables in c++?
Specify different types of decision control statements?
Write a program which employs Recursion
Can create new c++ operators?
Which software is used to run c++ program?
Write a short code using c++ to print out all odd number from 1 to 100 using a for loop