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
When you overload member functions, in what ways must they differ?
What is the difference between method overloading and method overriding in c++?
total amount of milk produced each morning and then calculates and outputs the number of cartons needed for this milk , the cost of producing the milk and the profit from producing this milk.
Is c++ pass by reference or value?
Why null pointer is used?
Is set c++?
Write a program in C++ for Fibonacci series
What are multiple inheritances (virtual inheritance)? What are its advantages and disadvantages?
What is heap sort in c++?
What is the prototype of printf function?
What is const pointer and const reference?
Can c++ do everything c can?
What are guid? Why does com need guids?
Is c++ an integer?
Evaluate the following expression as C++ would do :8 * 9 + 2 * 5 a) 82 b) 79 c) 370 d) list