write a program to insert an element into an array
Answer Posted / meena
/* Program to insert element into array */
#include<stdio.h>
#include<conio.h>
void main()
{
int arr[50],i,n,pos,num;
clrscr();
printf("How Many Elements:-");
scanf("%d",&n);
printf("\n\tEnter Elements into Array");
for(i=0;i<n;i++)
{
scanf("\t%d",&arr[i]);
}
printf("\nArray Elements before inserting");
for(i=0;i<n;i++)
{
printf("\n%d",arr[i]);
}
printf("\nEnter the position");
scanf("%d",&pos);
if(pos==0 || pos>=n)
{
printf("Invalid position");
}
else
{
printf("\nEnter the number you want to insert into an
array");
scanf("%d",&num);
/*shift the existing elements*/
for(i=n;i>=pos;i--)
arr[i]=arr[i-1];
arr[pos-1]=num;
printf("\nArray elements after insertion");
for(i=0;i<n;i++)
{
printf("\n%d",arr[i]);
}
}
getch();
}
| Is This Answer Correct ? | 57 Yes | 17 No |
Post New Answer View All Answers
Is c++ a high level language?
Explain function overloading and operator overloading.
How can you prevent accessing of the private parts of my class by other programmers (violating encapsulation)?
What are abstract data types in c++?
What is a singleton c++?
Can static member variables be private?
Can I learn c++ in a week?
What kind of jobs can I get with c++?
Why is main function important?
Where do I find the current c or c++ standard documents?
Explain how we implement exception handling in c++?
When the constructor of a base class calls a virtual function, why doesn't the override function of the derived class gets called?
How is data hiding achieved in c++?
Does c++ cost money?
What is the best it certification?