From c1f2201e94f795f444ec80aecfffef2f509c9a22 Mon Sep 17 00:00:00 2001 From: Shivam Singhal Date: Tue, 6 Jun 2017 12:50:27 +0530 Subject: [PATCH] Added union and intersection of 2 arrays. --- Intersection_of_2_arrays.cpp | 30 ++++++++++++++++++++++++++++++ Union_of_2_arrays.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 Intersection_of_2_arrays.cpp create mode 100644 Union_of_2_arrays.cpp diff --git a/Intersection_of_2_arrays.cpp b/Intersection_of_2_arrays.cpp new file mode 100644 index 000000000..e2c064e1b --- /dev/null +++ b/Intersection_of_2_arrays.cpp @@ -0,0 +1,30 @@ +#include +int main() +{ + int i,j,m,n; + cout <<"Enter size of array 1:"; + cin >> m; + cout <<"Enter size of array 2:"; + cin >> n; + int a[m]; + int b[n]; + cout <<"Enter elements of array 1:"; + for(i=0;i> a[i]; + for(i=0;i> b[i]; + i=0;j=0; + while((ib[j]) + j++; + else + { + cout << a[i++]<<" "; + j++; + } + } + return 0; +} diff --git a/Union_of_2_arrays.cpp b/Union_of_2_arrays.cpp new file mode 100644 index 000000000..4046e1ae8 --- /dev/null +++ b/Union_of_2_arrays.cpp @@ -0,0 +1,33 @@ +#include +int main() +{ + int m,n,i=0,j=0; + cout << "Enter size of both arrays:"; + cin >> m >> n; + int a[m]; + int b[n]; + cout << "Enter elements of array 1:"; + for(i=0;i>a[i]; + cout << "Enter elements of array 2:"; + for(i=0;i> b[i]; + i=0;j=0; + while((ib[j]) + cout << b[j++] <<" "; + else + { + cout << a[i++]; + j++; + } + } + while(i