Cartesian Product
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x,y,i,j;
cout<<"enter the size of first set : ";
cin>>x;
cout<<"Enter the size of second set : ";
cin>>y;
int a[x], b[y];
cout<<"Enter the elements of first set : ";
for(i=0;i<x;i++)
cin>>a[i];
cout<<"Enter the elements of second set : ";
for(i=0;i<y;i++)
cin>>b[i];
cout<<"\nCartesian product from A to B is :";
for(i=0;i<x;i++)
for(j=0;j<y;j++)
cout<<"{"<<a[i]<<","<<b[j]<<"}";
cout<<"\nCartesian product from B to A is :";
for(i=0;i<y;i++)
for(j=0;j<x;j++)
cout<<"{"<<b[i]<<","<<a[j]<<"}";
}
Comments
Post a Comment