Professional Documents
Culture Documents
Assign 7
Assign 7
ASSESSMENT
DESCRIPTION: Power set of a set is a set of all the subset of a set , for example let S={a,b}
then power set of s , P(s) = {{},{a},{b},{a,b}}
CODE:
#include <stdio.h>
#include <math.h>
void display(char *set, int set_size)
{
int counter, j;
int powset_size = pow(2, set_size);
printf("Power set is\n");
printf("{");
printf("' '");
for(counter = 0; counter < powset_size; counter++)
{
for(j = 0; j < set_size; j++)
{
if(counter & (1<<j))
printf("%c ", set[j]);
}
if(counter!=powset_size-1)
printf(",");
}
printf("}");
}
int main()
{
char set[50];
int n,i;
printf("Enter how many elements you want in set ");
scanf("%d",&n);
if(n==0)
{
printf("Power set is\n");
printf("{ }");
}
else
{
printf("Enter the elements ");
for(i=0;i<n;i++)
{
scanf("%s",&set[i]);
}
display(set, n);
}
return 0;
}
OUTPUT: