一:真值计算
主要考虑计算机如何表示逻辑演绎,且,或,非,蕴含,双条件。
从键盘输入两个命题P和Q的真值,求它们的合取、析取、条件和双条件的真值。用C语言实现。
二:集合的运算
集合的交,并,差,补,通过for,for双循环,类似命题:任意的x任意的y,都成立的一个表达式(x+y=y+x).每个x,都把所有y遍历一次。
一,用无序的办法表示集合,有非常多的检索。
#define _CRT_SECURE_NO_WARNINGS
#include
#include
//int creatjh(int *a[]);
void Both(int a[], int i, int b[], int j,int *c);
int Isin(int a,int b[],int n);
int IN(int a[],int i, int b[],int j,int *c);
void All(int a[], int i, int b[], int j, int *c);
void equal(int a[], int i, int ib[], int j);
int cdseris(int a[], int i, int b[], int j);
int main()
{
int jh1[10] = { 2,5,3,7,5 };
int jh2[10] = { 5,3,9,7,6 };
int jh3[10] = { 5,3,3,8,1,4};
int jh4[10] = { 5,3,3,6,6,4 };
int both[100] = { 0 };
int both2[100] = { 0 };
int both3[100] = { 0 };
int all1[20] = { 0 };
int all2[30] = { 0 };
int all3[40] = { 0 };
int e = 9;
int n1 = 10;
int n2=10,n3 = 10,n4=10;
int n5 = 20;
Isin(e, jh2, n2);
printf("\n");
All(jh1, n1, jh2, n2, all1);
printf("\n");
All(all1,n5, jh3,n3, all2);
printf("\n");
int cd=cdseris(jh4, n4, jh1, n1);
printf("\n");
equal(jh1, n1, jh4, n4);
return 0;
}
int Isin(int c, int b[],int n) {
int is;
for (int i = 0; i < n+1; i++) {
if (b[i] == c) {
is = 1;
break;
}
if (i == n) {
is = 0;
}
}
return is;
}
int IN(int a[], int i,int b[],int j,int *c) {
int v = 0;
for (int k = 0; k < i; k++)
{
int st = 0;
for (int ww = 0; ww < v+1; ww++)
{
if (c[ww] == a[k]) {
st = 1;
break;
}
}
if (st == 1)
{
continue;
}
for (int s = 0; s < j+1; s++)
{
if (b[s] == a[k])
{
break;
}
if (s == j)
{
c[v] = a[k];
printf("%d\t", c[v]);
v++;
}
}
}
}
int creatjh(int a[]) {
int j = 0;
int n = 0;
int y;
while (1) {
scanf("%d", &y);
if (y =='\0') {
break;
}
a[j++] = y;
n++;
}
return n;
}
void All(int a[], int i, int b[], int j, int *c) {
int bb = i > j ? i : j;
int v = IN(a, i, b, j, c);
for (int s = 0; s < j; s++)
{
int st = 1;
for (int ww = 0; ww < v; ww++)
{
if (c[ww]==b[s]) {
st = 0;
break;
}
}
if (st == 0) {
continue;
}
c[v] = b[s];
printf("%d\t", c[v]);
v++;
}
}
void Both(int a[], int mi, int b[], int nj, int *c){
int v = 0;
int st = 0;
int bb = mi > nj ? mi : nj;
for (int k = 0; k < mi; k++)
{
for (int ww = 0; ww < v+1; ww++) {
if (c[ww] == a[k]) {
st = 1;
break;
}
}
if (st == 1) {
continue;
}
for (int s = 0; s < nj; s++)
if (b[s] == a[k]) {
c[v] = a[k];
printf("%d\t", c[v]);
v++;
break;
}
}
}
int cdseris(int a[], int i, int b[], int j) {
int is=1;
for (int k = 0; k < i; k++) {
is = Isin(a[k], b, 10);
if (is == 0) {
printf("not cd seris\n");
break;
}
}
if (is == 1) {
printf("yes,is cd seris\n");
}
return is;
}
void equal(int a[], int i, int b[], int j){
int is = 0;
int iss = 0;
is = cdseris(a, i, b, j);
iss = cdseris(b, j, a, i);
if (is == 1 && iss == 1) {
printf("yes,is equal");
}
else
printf("no,is not equal");
}
二,用1,0表示法,可以快捷计算。
#define _CRT_SECURE_NO_WARNINGS
#include
#include
void display(int *aa, int *p);
void fei(int *aa,int *p);
void IN(int *a, int *b, int *p);
void Both(int *a, int *b, int *p);
void All(int *a, int *b, int *p);
int main()
{
int seris[10] = { 1,2,3,4,5,6,7,8,9,10 };
int sp[10] = { 11,22,33,44,55,66,77,88,99,100 };
int a[10] = { 1,0,0,1,1,0,0,1,1,0 };
int b[10] = { 0,0,1,1,0,0,1,1,0,0 };
for (int y = 0; y < 10; y++)
{
int q = seris[y];
int w = sp[y];
int e = a[y];
int r = b[y];
printf("%d\t", q);
printf("%d\t", w);
printf("%d\t", e);
printf("%d\t", r);
printf("\n");
}
display(a,seris);//display a
display(b,seris);
fei(a,seris);//not a
IN(a, b, seris);//a-b
Both(a, b, seris);//a^b
All(a, b, seris);
}
void display(int *aa,int *p) {
for (int i = 0; i < 10; i++)
if (aa[i] == 1) {
printf("%d", p[i]);
}
printf("\n");
}
void fei(int *a,int *p) {
int af[10] = { 0 };
for (int i = 0; i < 10; i++)
{
if (a[i] == 0) {
af[i] = 1;
}
}
for (int j = 0; j < 10; j++)
{
printf("%d", af[j]);
}
printf("\t");
display(af, p);
}
void IN(int *a, int *b,int *p) {
int a_b[10] = { 0 };
for (int i = 0; i < 10; i++)
if (a[i] == 1 && b[i] == 0) {
a_b[i] = 1;
}
for (int j = 0; j < 10; j++) {
printf("%d", a_b[j]);
}
printf("\t");
display(a_b, p);
}
void Both(int *a, int *b, int *p)
{
int ajb[10] = { 0 };
for (int i = 0; i < 10; i++)
if (a[i] == 1 && b[i] == 1) {
ajb[i] = 1;
}
for (int j = 0; j < 10; j++) {
printf("%d", ajb[j]);
}
printf("\t");
display(ajb, p);
}
void All(int *a, int *b, int *p) {
int ab[10] = { 0 };
for (int i = 0; i < 10; i++)
if (a[i] == 1 || b[i] == 1) {
ab[i] = 1;
}
for (int j = 0; j < 10; j++) {
printf("%d", ab[j]);
}
printf("\t");
display(ab, p);
}
这个时候,如何进行组合的计算呢?