#include<stdio.h>
#include<conio.h>
void main()
{ int a[10],b[10],c[20],i,j,n1,n2,k;
clrscr();
printf("\nenter total no. of elements
for first array:");
scanf("%d",&n1);
printf("\nenter elements");
for(i=0;i<n1;i++)
scanf("%d",&a[i]);
for(i=0;i<n1;i++)
printf("\ta[%d]=%d",i,a[i]);
printf("\nenter total no. of elements
for second array:");
scanf("%d",&n2);
printf("\nenter elements");
for(j=0;j<n2;j++)
scanf("%d",&b[j]);
for(j=0;j<n2;j++)
printf("\tb[%d]=%d",j,b[j]);
i=0;j=0;k=0;
while(i<n1 && j<n2)
{
if(a[i]<=b[j])
{
c[k]=a[i];
i++;
k++;
}
else
{
c[k]=b[j];
j++;
k++;
}
}
while(i<n1)
{
c[k]=a[i];
i++;
k++;
}
while(j<n2)
{
c[k]=b[j];
j++;
k++;
}
printf("\nnew array is");
for(k=0;k<n1+n2;k++)
printf("\tc[%d]=%d",k,c[k]);
getch();
}
No comments:
Post a Comment