C Programming Tutorial

Advertisements

Write a program to merge two arrays of same size in C++



       #include<iostream.h>
       #include<conio.h>
       void main()
       {
              int arr1[5],arr2[5],arr3[10],i,j,num;
              clrscr();

              cout<<"\nEnter values for array 1";
              for(i=0;i<5;i++)
              {
                 cout<<"\nEnter any number : "; 
                 cin>>arr1[i]; 
              }
              
              cout<<"\n\nEnter values for array 2";
              for(i=0;i<5;i++)
              {
                 cout<<"\nEnter any number : "; 
                 cin>>arr2[i]; 
              }
              
              cout<<"\nValues in array 1 : ";
              for(i=0;i<5;i++)
              cout<<arr1[i]<<" "<<;
              
              cout<<"\nValues in array 2 : ";
              for(i=0;i<5;i++)
              cout<<arr2[i]<<" "<<;
              
              for(i=0;i<5;i++)	
              {
		              arr3[i] = arr1[i];
		              arr3[i+5] = arr2[i];
              }

              cout<<"\nValues in array 3 : ";
              for(i=0;i<10;i++)
              cout<<arr3[i]<<" "<<;

              getch();
}

   Output : 

              Enter values for array 1 :
              Enter any number : 78
              Enter any number : 45
              Enter any number : 12
              Enter any number : 89
              Enter any number : 56
              
              Enter values for array 2 :
              Enter any number : 23
              Enter any number : 79
              Enter any number : 46
              Enter any number : 13
              Enter any number : 82
              
              Values in array 1 : 78 45 12 89 56
              Values in array 2 : 23 79 46 13 82
              Values in array 3 : 78 45 12 89 56 23 79 46 13 82




Advertisement