What is Cartesian product of two set:-
if set A={1,2} and set B={4,5,6,7} then Cartesian product of set A and B is :-
A*B={ (1,4),(1,5),(1,6),(1,7),(2,4),(2,5),(2,6),(2,7) }
#include<stdio.h>
int main()
{
int a[10],b[10],n1,n2,i,j;
printf("Enter size of set A\n");
scanf("%d",&n1);
printf("Enter element of set A\n");
for(i=0;i<n1;i++)
scanf("%d",&a[i]);
printf("Enter size of set B\n");
scanf("%d",&n2);
printf("Enter element of set B\n");
for(i=0;i<n2;i++)
scanf("%d",&b[i]);
// logic for cartesian product
printf("{");
for(i=0;i<n1;i++)
{
for(j=0;j<n2;j++)
{
printf(" (%d %d) ",a[i],b[j]);
}
}
printf("}");
return 0;
}
No comments:
Post a Comment