Home > Back-end >  Help you how to use C language to achieve: please set A subset of the problem.
Help you how to use C language to achieve: please set A subset of the problem.

Time:10-18


This program has five functions, the former four functions you can need not ignore, now want to you help me to solve is the realization of the function of the fifth,


 
# include & lt; Stdio. H>
# include & lt; String. H>
# include & lt; Math. H>
# define N 100

Int b [32]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32};


Unsigned huanerjinzhi (int a [], unsigned d)
{
int i=0;
Unsigned int count=0;
While (d)
{
A [I]=d % 2;
D=d/2;
i++;
count++;
}
Return the count.
}
/* into binary */


Unsigned power (unsigned I, unsigned n)
{
Unsigned j, s=1;
for (j=0; J & lt; n; J++)
S=s * I;
return s;
}
/* count 2 NTH power function */


Void jisuan (unsigned n)
{
Unsigned I, j, t;
Int a, [32].
For (I=1; I & lt; Power (2, n); I++)
{
Printf (" {");
T=huanerjinzhi (a, I);
For (j=0; J & lt; t; J++)
If (a [j]==1 & amp; & I & lt; Power (2, n) - 1)
Printf (" % d, b [j]);
Printf ("} \ n ");
}
}
/* determine output */


The main () {
Int a [N], b [N], c [N], [N] d;
Int [N] aa and bb [N].
Int I, j, k=1;
Int x=1, y=1, z;
int m,n;
Int flag;


Int q;
Printf (" please select mode: \ n1. U B \ n2 studying B \ n3 A - B \ n4 interchange A triangle does not let play B \ n5 P (A) the collection of values and the base number \ n ");
The scanf (" % d ", & amp; Q);
//mode selection
If (q!=5) {//judgment model types, will be the first four groups to
Printf (" please entered A set of element number: \ n ");
The scanf (" % d ", & amp; M);
Printf (" please entered A set of element: \ n ");
for(i=1; i<=m; I++) {
The scanf (" % d ", & amp; A [I]);
}
//read A collection
Printf (" please lose the B set of element number: \ n ");
The scanf (" % d ", & amp; N);
Printf (" please lose into the collection element: B \ n ");
for(i=1; i<=n; I++) {
The scanf (" % d ", & amp; B [I]);
}
//read array B
for(i=1; i<=m; I++) {
flag=0;
for(j=1; J<=n; J++) {
If (a==b [j] [I]) {c=[k] a [I]; k++; Flag=1; continue; }
}
If (flag==0) {
Aa=[x] a [I]; X++; }
}/AB/o intersection, and part of A - B
for(i=1; i<=n; I++) {
flag=0;
for(j=1; J<=m; J++) {
If (a==b [j] [I]) {flag=1; continue; }
}
If (flag==0) {
Bb [y] [I]=b; Y++; }
}
}//o B - A part of the



The switch (q) {//switch judgment model
Unsigned int n;
Int s;

Case 1:
Printf (" and set the base value of the A and B: A total of % d \ n ", x + y + k - 3);
Printf (" {");
for(i=1; ifor(i=1; ifor(i=1; iPrintf (" % d}, "[c] k - 1);
printf("\n");//for A ∪ B
break;
Case 2:
Printf (" the intersection of A and B are the base of value: A total of % d \ n ", k - 1);
Printf (" {");
for(i=1; iPrintf (" % d}, "[c] k - 1);
printf("\n");//for A studying B
Case 3:
Printf (" A - B and the base of the intersection of value: A total of % d \ n ", x - 1);
Printf (" {");
for(i=1; iPrintf (" % d} ", aa] [x - 1);
printf("\n"); A - B/o with the intersection of A
break;
Case 4:
Printf (" base "of the symmetric difference of A and B values: A total of % d \ n", x + y - 2);
Printf (" {");
for(i=1; ifor(i=1; iPrintf (" % d} ", bb [1] y);
printf("\n");//for symmetric difference of A and B
break;

Case 5:
Printf (" please enter P (A) the number of elements in the collection: ");

The scanf (" % d ", & amp; S);
S=pow (2 s);

Printf (" please enter P (A) A collection of value: ");
The scanf (" % ud ", & amp; N);
While (n)
{
Printf (" {} \ n ");
Jisuan (n);
The scanf (" % ud ", & amp; N);
Printf (" base value of % d \ n ", s + 1);
}


}

Printf (" continue running Y/N: ");
The fflush (stdin);
The scanf (" % c ", & amp; k);
If (k=='n' | | k=='n') return;
The fflush (stdin);
The main ();

return 0;
}



Run results screenshot below

  • Related