Thursday, 18 July 2013

Program in C to Merge Two Arrays into Sorted Array

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],b[10],c[20],m,n,i,j,temp=0;
clrscr();
printf(“Entrer the size of array A\n”);
scanf(%d”,&m);
printf(“Enter the sorted element of Array A\n”);
for(i=0;i<m;i++)
{
scanf(“%d”,&a[i]);
}
printf(“Enter the size of array B\n”);
scanf(“%d”, &n);
printf(“Enter the sorted element of Array B\n”);
for(i=0;i<n;i++)
{
scanf(%d”,&b[i]);
}
for(i=0;i<5;i++)
{
c[i]=a[i];
c[i+5]=b[i];
}
printf(“Merge Array is \n”);
for(i=0;i<n;i++)
{
for(j=i+1;j<10;j++)
{
if(c[i]>c[j])
{
temp=c[i];
c[i]=c[j];
c[j]=temp;
}
}
}
for(i=0;i<10;i++)
{
printf(“%d”, c[i]);
}
getch();

}

No comments:

Post a Comment