#include<stdio.h>

void findIntersection(int arr1[], int m, int arr2[], int n)
{
    // An array to store the intersection elements
    int intersection_array[50] = {0};
    int counter = 0;
    
    int i = 0, j = 0;
    
    // Loop through the elements
    while (i < m && j < n)
    {
        if (arr1[i] > arr2[j])
        {
            // Increase iterator for array 2
            j++;
        }
        else if (arr2[j] > arr1[i])
        {
            // Increase iterator for array 1
            i++;
        }
        else
        {
            intersection_array[counter] = arr1[i];
            counter++;
            
            // Increment counter for both arrays
            i++;
            j++;
        }
    }
    
    for(i = 0; i<counter; i++)
        printf("%d ",intersection_array[i]);
}

int main(void)
{
	int arr1[] = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20};
	int arr2[] = {3, 6, 9, 12, 15, 18, 21};
	
	findIntersection(arr1, 10, arr2, 7);
	
	return 0;
}