#include "stdio.h"
#include "conio.h"
#include "alloc.h"
void main()
{
int *a,*b,*c,i,j,m,n,temp;
clrscr();
printf("How many elements are there in array first? ");
scanf("%d",&m);
a=(int *)malloc(m*sizeof(int));
printf("\nEnter The Elements of Array first:\n");
for(i=0;i
printf("\nHow many elements are there in array Second? ");
scanf("%d",&n);
b=(int *)malloc(n*sizeof(int));
printf("\nEnter The Elements of Array Second:\n");
for(i=0;i
printf("\nSorting Both Arrays...\n");
for(i=0;i
if(a[j] {
temp=a[j];
a[j]=a[j-1];
a[j-1]=temp;
}
for(i=0;i
if(b[j] {
temp=b[j];
b[j]=b[j-1];
b[j-1]=temp;
}
c=(int *)malloc((m+n)*sizeof(int));
printf("\nCopying First array to Third array....\n");
for(i=0;i
printf("\nCopying Second array to Third array...\n");
for(i=m,j=0;i<(m+n);i++,j++)
c[i]=b[j];
printf("\nNow Printing Third array...\n");
for(i=0;i<(m+n);i++)
printf("%d\t",c[i]);
free(a);
free(b);
free(c);
getch();
}
Friday, June 26, 2009
PROGRAM TO SORT 2 ARRAYS AND MERGE THEM INTO A SINGLE ARRAY
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment