#include <stdio.h>

// 逻辑与 int logic_and(int a, int b) { return a && b; }

// 逻辑或 int logic_or(int a, int b) { return a || b; }

// 逻辑非 int logic_not(int a) { return !a; }

// 逻辑异或 int logic_xor(int a, int b) { return (a && !b) || (!a && b); }

// 条件语句 int logic_if(int a, int b) { return !a || b; }

int main() { int a, b, c; printf("请输入三个命题变元的取值(0或1,空格隔开):"); scanf("%d %d %d", &a, &b, &c);

printf("真值表如下:\n");
printf("A   B   C   AND  OR   NOT  XOR  IF\n");
printf("%d   %d   %d   %d    %d    %d    %d    %d\n", a, b, c, logic_and(a, b), logic_or(a, b), logic_not(a), logic_xor(a, b), logic_if(a, b));

return 0;

}

C语言实现逻辑联结词真值表生成器 - 包含AND、OR、NOT、XOR、IF

原文地址: https://www.cveoy.top/t/topic/rTX 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录