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
the first character in the variable name must be an a) special symbol b) number c) alphabet
What are c++ manipulators?
What is flush () in c++?
What function initalizes variables in a class: a) Destructor b) Constitutor c) Constructor
What is the difference between while and do while loop? Explain with examples.
Why do we need function?
Why should you learn c++?
write asingle linked list which read from two list & the do the following 1 sort the prime & nonprime num (prime should be less tn nonprime) 2 each node has a prime num followd by nonprime 3 add a new node into its sutable plce 4 erase the most three duplicated non prime num 5 find the least duplicated prime num
What is a wchar_t in c++?
What is the importance of mutable keyword?
Can we use this pointer in a class specific, operator-overloading function for new operator?
Explain explicit container.
What are pointer-to-members in C++? Give their syntax.
What is runtime errors c++?
What is extern c++?