#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,a[5],b[5],c[10],max=5,t;
clrscr();
printf("Enter list in sorted order:");
printf("\nEnter value in list 1:\n");
for(i=0;i<max;i++)
{
printf("Enter element %d: ",i+1);
scanf("%d",&a[i]);
}
printf("\nEnter value in list 2:\n");
for(i=0;i<max;i++)
{
printf("Enter element %d: ",i+1);
scanf("%d",&b[i]);
}
i=0;
j=0;
k=0;
while(i<max && j<max)
{
if(a[i]<b[j])
{
c[k]=a[i];
i++;
}
else
{
c[k]=b[j];
j++;
}
k++;
}
while(i<max)
{
c[k]=a[i];
k++;
i++;
}
while(j<max)
{
c[k]=b[j];
k++;
j++;
}
for(i=0;i<k;i++)
{
printf("\n%d",c[i]);
}
getch();
}
#include<conio.h>
void main()
{
int i,j,k,a[5],b[5],c[10],max=5,t;
clrscr();
printf("Enter list in sorted order:");
printf("\nEnter value in list 1:\n");
for(i=0;i<max;i++)
{
printf("Enter element %d: ",i+1);
scanf("%d",&a[i]);
}
printf("\nEnter value in list 2:\n");
for(i=0;i<max;i++)
{
printf("Enter element %d: ",i+1);
scanf("%d",&b[i]);
}
i=0;
j=0;
k=0;
while(i<max && j<max)
{
if(a[i]<b[j])
{
c[k]=a[i];
i++;
}
else
{
c[k]=b[j];
j++;
}
k++;
}
while(i<max)
{
c[k]=a[i];
k++;
i++;
}
while(j<max)
{
c[k]=b[j];
k++;
j++;
}
for(i=0;i<k;i++)
{
printf("\n%d",c[i]);
}
getch();
}
No comments:
Post a Comment