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
the maximum length of a character constant can be a) 2 b) 1 c) 8
Mention the storage classes in c++.
Is c++ fully object oriented?
What is the benefit of learning c++?
what is upcasting in C++?
Explain the volatile and mutable keywords.
What is the sequence of destruction of local objects?
What is function prototyping? What are its advantages?
Assume an array of structure is in order by studentID field of the record, where student IDs go from 101 to 500. Write the most efficient pseudocode algorithm you can to find the record with a specific studentID if every single student ID from 101 to 500 is used and the array has 400 elements. Write the most efficient pseudocode algorithm you can to find a record with a studentID near the end of the IDs, say in the range from 450 to 500, if not every single student ID in the range of 101 to 500 is used and the array size is only 300
What is singleton pattern in c++?
Why cout is used in c++?
Specify some guidelines that should be followed while overloading operators?
Explain binary search.
What are the extraction and insertion operators in c++?
What is the exit function in c++?