Skip to content

Instantly share code, notes, and snippets.

@sodabrew
Created September 13, 2017 23:49
Show Gist options
  • Save sodabrew/4cbf2617ef0d24be57103857756fcd6b to your computer and use it in GitHub Desktop.
Save sodabrew/4cbf2617ef0d24be57103857756fcd6b to your computer and use it in GitHub Desktop.
int a[] = { 1,2,3,4,5,6,7,8,9 };
int b[] = { 2,4,8,12,16,18 };
int *c;
int main() {
int i, j, k;
c = malloc(sizeof(a) + sizeof(b));
for (i = 0, j = 0, k = 0; i < sizeof(a)/sizeof(int) && j < sizeof(b)/sizeof(int); ) {
if (a[i] == b[j]) {
c[k] = a[i];
i++, j++, k++;
} else if (a[i] < b[j]) {
i++;
} else if (a[i] > b[j]) {
j++;
}
}
for (int l = 0; l < k; l++) {
printf("%d\n", c[l]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment