Tuesday, 20 December 2016

Write a program to merge two array into a single array?

Q : Write a program to merge two array into a single array?

/*     #################################
           Girfa Student Help
           Merge two Array
           Programmber : Vishal
           For more program visit : http://girfahelp.blogspot.in/p/c-language.html
       #################################
*/
#include<stdio.h>
#include<conio.h>
#define MAX 5
void main()
{
       int a1[MAX],a2[MAX],a3[MAX*2];
       int i,j;
       clrscr();
       puts("First Array Input");
       for(i=0;i<MAX;i++)

       {
              printf("Enter %d Position number>> ",i+1);
              scanf("%d",&a1[i]);
       }
       puts("Second  Array Input");
       for(i=0;i<MAX;i++)
       {
              printf("Enter %d Position number>> ",i+1);
              scanf("%d",&a2[i]);
       }
       /* Merge */
       for(i=0;i<MAX;i++)
              a3[i]=a1[i];
       for(j=i,i=0;i<MAX;i++,j++)
              a3[j]=a2[i];
       puts("\nFirt Array");
       for(i=0;i<MAX;i++)
       printf("\t%d",a1[i]);
       puts("\nSecond Array");
       for(i=0;i<MAX;i++)
       printf("\t%d",a2[i]);
       puts("\nMerge Array");
       for(i=0;i<MAX*2;i++)
       printf("\t%d",a3[i]);
       getch();

}



No comments:

Post a Comment