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


Please Help Members By Posting Answers For Below Questions

Can manipulators fall in love?

568


What are the restrictions apply to constructors and destructors?

645


Can you pass an array to a function in c++?

545


Define a nested class. Explain how it can be useful.

638


Can I uninstall microsoft c++ redistributable?

611






What is c++ virtual inheritance?

599


What is the use of structure in c++?

555


In int main(int argc, char *argv[]) what is argv[0] a) The first argument passed into the program b) The program name c) You can't define main like that

618


What is the use of seekg in c++?

599


Write a Program for dynamically intialize a 2 dimentional array. Eg:5x20, accept strings and check for vowels and display the no.finally free the space allocated .

686


Do you know what is overriding?

619


How do I make turbo c++ full screen?

588


What is a node class in c++?

648


What is a multiset c++?

555


Can a program run without main function?

623