Mar
28
2008

C++ Program to perform the array operations

C++ Program to perform the following array operations.

  • Insertion
  • Deletion
  • Traversing
  • Merge two arrays
/**************************************************************	
	Author: Arun Vishnu M V
	Web: www.arunmvishnu.com
	Description: Program to perform the following array operations.
		a) Insertion
		b) Deletion
		c) Traversing
		d) Merge two arrays
***************************************************************/
#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{
	int array1[150],array2[150],array3[300],i,j,n1,n2,position;
	int element,choice,n3;
	clrscr();
	cout<<"How many elements in the array: ";
	cin>>n1;
	cout<<"Enter "<>array1[i];
	}
	clrscr();
	while(1)
	{
      clrscr();
		cout<<"1: To add an element.";
		cout<<"\n2: To delete an element.";
		cout<<"\n3: Display array elements.";
		cout<<"\n4: Merge two arrays.";
		cout<<"\n5: Exit";
		cout<<"\nEnter tour choice: ";
		cin>>choice;

		switch(choice)
		{
			case 1:		// Insertion
				cout<<"\t\tInsertion\n";
				cout<<"Enter a position to insert: ";
				cin>>position;
				if(position<0 || position>=150 && n1>149)
				{
					cout<<"Error in position!\nRe-enter your choice.";
					getch();
					break;
				}
				cout<<"Enter the element to insert: ";
				cin>>element;
				for(i=n1;i>=position;i--)
					array1[i]=array1[i-1];
				array1[i]=element;
				cout<<"New elemet is inserted successfully!";
				n1=n1+1;
				getch();
				break;
			case 2:               // Deletion
				cout<<"\t\tDeletion\n";
				cout<<"Enter a position to delete: ";
				cin>>position;
				for(i=position;i>n2;
				cout<<"Enter "<>array2[j];
				for(i=0;i

Related Posts

Author: Arun Vishnu

Leave a comment

Archives

Highslide for Wordpress Plugin