write a program to insert an element into an array
Answer Posted / abhishek
This is just perfect, i compiled it right now!!
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,n,ent,ins;
clrscr();
printf(" enter how many nos u wanna putin");
scanf("%d",&n);
if(n<1||n>20)
{
printf(" invalid input");
return;
}
printf(" Enter the elements into the array one by one");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("the elements in the array");
for(i=0;i<n;i++)
{
printf("%d",a[i]);
}
printf(" Which address field will occupy the new element");
scanf("%d",&ins);--ins;
printf(" enter the elemnt u wanna put in");
scanf("%d",&ent);
for(i=n;i>=ins;i--)
{
a[i+1]=a[i];
}
a[ins]=ent; n++;
printf(" the new array after insertion of nu elemnt");
for(i=0;i<n;i++)
{
printf("%d",a[i]);
}
getch();
}
| Is This Answer Correct ? | 4 Yes | 6 No |
Post New Answer View All Answers
Can we sort map in c++?
Is java based off c++?
What is the use of setfill in c++?
How can you tell what shell you are running on unix system?
How can you create a virtual copy constructor?
Why should you learn c++?
What is c++ course?
What is constructor c++?
If I is an integer variable, which is faster ++i or i++?
What are stacks? Give an example where they are useful.
What is c++ coding?
Explain explicit container.
What are the new features that iso/ansi c++ has added to original c++ specifications?
Explain what are accessor methods?
What are the types of pointer?