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 manipulators fall in love?
What are the restrictions apply to constructors and destructors?
Can you pass an array to a function in c++?
Define a nested class. Explain how it can be useful.
Can I uninstall microsoft c++ redistributable?
What is c++ virtual inheritance?
What is the use of structure in c++?
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
What is the use of seekg in c++?
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 .
Do you know what is overriding?
How do I make turbo c++ full screen?
What is a node class in c++?
What is a multiset c++?
Can a program run without main function?