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

When you overload member functions, in what ways must they differ?

1048


What is the difference between method overloading and method overriding in c++?

1151


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.

2585


Is c++ pass by reference or value?

1075


Why null pointer is used?

1049


Is set c++?

1003


Write a program in C++ for Fibonacci series

1211


What are multiple inheritances (virtual inheritance)? What are its advantages and disadvantages?

1058


What is heap sort in c++?

1074


What is the prototype of printf function?

1187


What is const pointer and const reference?

1167


Can c++ do everything c can?

1088


What are guid? Why does com need guids?

1055


Is c++ an integer?

1039


Evaluate the following expression as C++ would do :8 * 9 + 2 * 5 a) 82 b) 79 c) 370 d) list

1004