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
Write a program in c++ to print the numbers from n to n2 except 5 and its multiples
Describe private, protected and public – the differences and give examples.
what is C++ objects?
What is an accessor in c++?
How many standards of c++ are there?
What is the need of a destructor?
Define linked lists with the help of an example.
Why #include is used?
What are the uses of static class data?
When does a 'this' pointer get created?
C is to C++ as 1 is to a) What the heck b) 2 c) 10
give me an example for testing a program showing the test path .show how the test is important and complex.
Does there exist any other function which can be used to convert an integer or a float to a string?
What is the role of copy constructor in copying of thrown objects?
Define virtual constructor.