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
Explain the difference between overloading and overriding?
What are member functions used in c++?
Difference between pointer to constant and constant pointer to a constant. Give example.
Do you know about C++ 11 standard?
Is eclipse good for c++?
How a new element can be added or pushed in a stack?
Do you know the problem with overriding functions?
Differences between private, protected and public and give examples.
What are 2 ways of exporting a function from a dll?
What is the extraction operator and what does it do?
what is COPY CONSTRUCTOR and what is it used for?
What is array in c++ pdf?
A mXn matrix is given and rows and column are sorted as shown below.Write a function that search a desired entered no in the matrix .with minimum complexity 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
What is a Default constructor?
Explain about templates of C++.