Run
#include <stdio.h>
int main(){
int arr1[]={2, 6, 7, 8};
int n = sizeof(arr1)/sizeof(arr1[0]);
int arr2[]={10, 12, 17, 18, 90, 91};
int m = sizeof(arr2)/sizeof(arr2[0]);
int i = 0, j=0, count =0, m1=-1, m2=-1;
for (; count <= (n + m)/2; count++)
{
m2=m1;
if(i != n && j != m)
{
m1 = (arr1[i] > arr2[j]) ? arr2[j++] : arr1[i++];
}
else if(i < n)
{
m1 = arr1[i++];
}
else
{
m1 = arr2[j++];
}
}
if((n + m) % 2 == 1)
printf("%d ", m1);
else
printf("%d ", (m1+m2)/2);
}
Login/Signup to comment