Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

How does a C++ structure differ from a C++ class?

1072


Explain 'this' pointer and what would happen if a pointer is deleted twice?

1014


What is the oldest programming language?

946


What are the advantages of using a pointer?

1021


Assume studentNames and studentIDs are two parallel arrays of size N that hold student data. Write a pseudocode algorithm that sorts studentIDs array in ascending ID number order such that the two arrays remain parallel.

2145


Explain one-definition rule (odr).

1064


What is null pointer and void pointer?

1005


What is difference between c++ 11 and c++ 14?

1011


Do you need a main function in c++?

1072


What is class syntax c++?

1085


What is the type of 'this' pointer?

969


What does h mean in maths?

1103


How do you differentiate between overloading the prefix and postfix increments?

1039


What is diamond problem in c++?

947


Write a program using shift_half( ) function to shift the elements of first half array to second half and vice versa.

1265