From 36f3c96e464cbef53a9f1729657846d4bdfff018 Mon Sep 17 00:00:00 2001 From: Jeremias Moreira Gomes <j3r3miasmg@gmail.com> Date: Tue, 30 Oct 2018 03:43:17 -0300 Subject: [PATCH] Intersection between two lists in C. --- .../arrayIntersection.c | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Intersection of two Integer arrays/arrayIntersection.c diff --git a/Intersection of two Integer arrays/arrayIntersection.c b/Intersection of two Integer arrays/arrayIntersection.c new file mode 100644 index 0000000..f9e78e5 --- /dev/null +++ b/Intersection of two Integer arrays/arrayIntersection.c @@ -0,0 +1,33 @@ +#include <stdio.h> + +int main() +{ + int sa, sb; + printf("Inform the size of the first list: "); + scanf("%d", &sa); + int ma[sa]; + printf("Inform the size of the second list: "); + scanf("%d", &sb); + int mb[sb]; + printf("Inform the list of integers space separated:\n"); + for (int i = 0; i < sa; i++) { + scanf("%d", &ma[i]); + } + printf("Inform the list of integers space separated:\n"); + for (int i = 0; i < sb; i++) { + scanf("%d", &mb[i]); + } + + printf("Intersection between first and second list:\n"); + for (int i = 0; i < sa; i++) { + for (int j = 0; j < sb; j++) { + if (ma[i] == mb[j]) { + printf("%d ", ma[i]); + break; + } + } + } + printf("\n"); + + return 0; +}