"Z Code Writer" is an Online Blog for Programmer & Beginner. Here, You will Find tech, Build your Programming Skills and other Programming Language Like C, C++, HTML, Java Script Java Code, Web Designing and University Of Sialkot (USKT) CGPA / GPA Calculator etc.

Saturday, 3 August 2019

Union Of Set A and B Source Program

Write a program  to calculate Union of set A and B in C++. 



#include <iostream>
#include <conio.h>
using namespace std;

void setting(int r[],int r1){

for(int i=0;i<r1;++i)
for(int j=i+1;j<r1;)
{
if(r[i]==r[j])
{
for(int k=j;k<r1-1;++k)
r[k]=r[k+1];
--r1;
}
else
++j;
}
int t;
for (int i=0;i<r1-1;i++)
{
for (int j=i;j<r1;j++)
if(r[i]>r[j])
{
t=r[i];
r[i]=r[j];
r[j]=t;
}
}
cout<<" Union of set A & B\n\n A U B = {";
for(int i=0;i<r1;i++)
{
cout<<r[i];
if(i<(r1-1))
{
cout<<", ";
}
}
cout<<"}";
}

// Union 

int Union(){
int n=0,m=0,o=0;
cout<<" Enter size of set A :  ";
cin>>n;
cout<<" Enter size of set B :  ";
cin>>m;
o=n+m;
int a[n], b[m], u[o];
cout<<" Enter elements of set A \n\n";
for(int i=0;i<n;i++)

cin>> a[i];
}
cout<<" Enter elements of set B \n\n";
for(int i=0;i<m;i++)
{
cin>> b[i];
}
for(int i=0;i<n;i++)
{
u[i]=a[i];
}
int k=0;
for(int i=n;i<o;i++)
{
u[i]=b[k];
k++;
}
setting(u,o);
}

int main(){
cout<<"\t ***** UNION ***** \n";
Union();
getch();
return 0;
}
Click Here To Download .CPP File

No comments:

Post a Comment

Thanks For Visiting Here...!! I will Reply you as soon as possible.