in a cricket game the two teams a and b have different characteristics of players in terms of batsman and bowlers. find similar characteristics of players using union operation. write a program for set operation using pointers.
#include<stdio.h>
int *a,*b;
int x,y,z,size_of_a,size_of_b;
//The function is finding the union of two given sets
void finding_union()
{
int *player=(int *)malloc((size_of_a+size_of_b)*sizeof(int));
x=0;//Holding the maximum union set
for(y=0;y<size_of_a;y++)
player[x++]=a[y];
for(y=0;y<size_of_b;y++)
{
int i=0; //Flag for copying elements
for(z=0;z<size_of_a;z++)
{
if(a[z]==b[y])
i=1;//keeping track if element is present or absent
}
if(i==0)
player[x++]=b[y];
}
printf("\nThe resulting union of the two set is \n");
for(y=0;y<x;y++)//display the union set
printf("%d\t",player[y]);
}
int main()
{
size_of_a = 11; //The cricket is being played by 11 players per each team
size_of_b = 11; //The cricket is being played by 11 players per each team
a=(int *)malloc(size_of_a*sizeof(int));
b=(int *)malloc(size_of_b*sizeof(int));
printf("Enter the players of team a\n");
for(x=0;x<size_of_a;x++)
scanf("%d",&a[x]);
printf("Enter the players of team b\n");
for(x=0;x<size_of_b; x++)
scanf("%d",&b[x]);
finding_union();
free(a);
free(b);
}
Comments
Leave a comment