Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to find the common numbers but i only keep getting 2 out of the four. The common numbers are 1,2,3,5 and I only

I need to find the common numbers but i only keep getting 2 out of the four. The common numbers are 1,2,3,5 and I only get 3 and 5.: (C PROGRAM)

#include

int printIntersection(int arr1[], int arr2[], int m, int n)

{

int i = 0, j = 0;

while (i < m && j < n)

{

if (arr1[i] < arr2[j])

i++;

else if (arr2[j] < arr1[i])

j++;

else

{

printf(" %d ", arr2[j++]);

i++;

}

}

}

int main()

{

int arr1[] = { 1, 2, 3, 4, 5 };

int arr2[] = { 3, 1, 5, 6, 2 };

int m = sizeof(arr1) / sizeof(arr1[0]);

int n = sizeof(arr2) / sizeof(arr2[0]);

printIntersection(arr1, arr2, m, n);

getchar();

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Probabilistic Databases

Authors: Dan Suciu, Dan Olteanu, Christopher Re, Christoph Koch

1st Edition

3031007514, 978-3031007514

More Books

Students also viewed these Databases questions

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago