2/23/2009

C Program To Perform Merging Of Two Arrays


/* C Program To Perform Merging Of Two Arrays */
#include<stdio.h>
#include<conio.h>
void main()
{
  int i,j,n,m,a[5],b[5],c[10];
  clrscr();
 printf("Enter the size of an array A\n");
  scanf("%d",&m);
 printf("Enter the element of the array A\n");
 for(i=0;i<m;i++)
  scanf("%d",&a[i]);
 printf("Enter the size of an array B\n");
  scanf("%d",&n);
 printf("Enter the element of the array B\n");
 for(i=0;i<n;i++)
  scanf("%d",&b[i]);
 printf("Array A is\n");
 for(i=0;i<m;i++)
  printf("%d ",a[i]);
    printf("\n");
 printf("Array B is\n");
 for(i=0;i<n;i++)
  printf("%d ",b[i]);
    printf("\n");
 //formulla part
 for(i=0;i<m;i++)
  c[i]=a[i];
  i=m;
  j=0;

   while(i<(m+n))
    {
       c[i]=b[j];
       j++;
       i++;
    }
  printf("The merged array is\n");
  for(i=0;i<(m+n);i++)
   printf("%d ",c[i]);
       printf("\n");

getch();
}
Out Put:
C Program To Perform Merging Of Two Arrays

No comments:

Post a Comment