#include <iostream>
#include <bits/stdc++.h>
using namespace std;
void sortedMerge(int a[], int b[], int res[], int n, int m)
{
int i = 0, j = 0, k = 0;
while (i < n)
{
res[k] = a[i];
i += 1;
k += 1;
}
while (j < m)
{
res[k] = b[j];
j += 1;
k += 1;
}
sort(res, res + n + m);
}
int main()
{
int a[10], b[10];
int na, nb, i;
int intersection[10], unions[10];
cout<< "Enter number of elements of set A: ";
cin >> na;
cout<< "Enter number of elements of set B: ";
cin >> nb;
cout<< "\nEnter elements of set A\n";
for(i=0; i<na; i++)
{
cout<< "Enter " <<i+1 <<" Element: ";
cin>> a[i];
}
cout<< "\nEnter elements of set B\n";
for(i=0; i<nb; i++)
{
cout<< "Enter " <<i+1 <<" Element: ";
cin>> b[i];
}
int res[na + nb];
sortedMerge(a, b, res, na, nb);
cout<< "\nIntersection: { ";
for (i = 0; i < na + nb; i++)
{
if(res[i]==res[i+1])
{
intersection[i] = res[i];
cout<< intersection[i] <<" ";
}
}
cout<< "}\n";
cout<< "Union: { ";
for (i = 0; i < na + nb; i++)
{
if(res[i]!=res[i+1])
{
unions[i] = res[i];
cout<< unions[i] <<" ";
}
}
cout<< "}";
return 0;
}