A. 真值表的如何用c语言表示
呵呵,简单啊,你自定义一些符号为与 、或等,在菜单写明就行代表什么就行啊
B. 如何用C语言做出“构造命题公式的真值表”的程序~
const int p[]={0,0,1,1};
const int q[]={0,1,0,1};
int i;
printf("p 合取 q 结果\n");
for(i=0;i<4;i++)
{
if(p[i]==0 || q[i]==0)
{
printf("%d %d 0\n",p[i],q[i]);
}
else
{
printf("%d %d 1\n",p[i],q[i]);
}
}
printf("p 析取 q 结果\n");
for(i=0;i<4;i++)
{
if(p[i]==1 || q[i]==1)
{
printf("%d %d 1\n",p[i],q[i]);
}
else
{
printf("%d %d 0\n",p[i],q[i]);
}
}
printf("p 单条件 q 结果\n");
for(i=0;i<4;i++)
{
if(p[i]==1 && q[i]==0)
{
printf("%d %d 0\n",p[i],q[i]);
}
else
{
printf("%d %d 1\n",p[i],q[i]);
}
}
printf("p 双条件 q 结果\n");
for(i=0;i<4;i++)
{
if((p[i]==1 && q[i]==1) || (p[i]==0 && q[i]==0))
{
printf("%d %d 1\n",p[i],q[i]);
}
else
{
printf("%d %d 0\n",p[i],q[i]);
}
}
//运行结果:
p 合取 q 结果
0 0 0
0 1 0
1 0 0
1 1 1
p 析取 q 结果
0 0 0
0 1 1
1 0 1
1 1 1
p 单条件 q 结果
0 0 1
0 1 1
1 0 0
1 1 1
p 双条件 q 结果
0 0 1
0 1 0
1 0 0
1 1 1
//是这个意思吗?
C. 如何用c编写简单的离散数学合式公式真值表
#include <stdio.h>
int main()
{
char p[10],q[10];
char pandq,porq;
puts("输入P,Q的值(T或者F)");
scanf("%s%s",p,q);
if(p[0]=='T'&&q[0]=='T')pandq='T';
else pandq='F';
if(p[0]=='F'&&q[0]=='F')porq='F';
else porq='T';
printf("PVQ=%c P∧Q=%c\n",porq,pandq);
return 0;
}
/*
合式公式是什么啊?
告诉我,我帮助你写
如P→(PVQ)等等PVQ是当P和Q同时为F是PVQ为F,否则为T,P∧Q是当P和Q同时为T时P∧Q为T,否则为F,P→Q是当P为T,Q为F是P→Q为F,否则为T,P←→Q是当P和Q相同是为T,否则为F
PVQ
Q F T
P
F F T
T T T
P∧Q
Q F T
P
F F F
T F T
这样行吗,你画一下表格吧
*/
D. 用C语言实现(p→q)→(!p∧!r)的真值表
摘要 (P∧(P->Q))->Q
E. 用C语言编程:输入命题公式的合式公式,求出公式的真值表,并输出该公式的主合取范式和主析取范式
A-Z + is OR * is AND _ is → # is⊕(圆圈里加个+) @ is ⊙
$ is ↑ 命题的"与非" 运算( "与非门" )
% is ↓ 命题的"或非"运算( "或非门" )
Input the source formula:
A*!S+R
NORMALc: (!A*!B*!R)+(A*!B*!R)+(!A*B*!R)+(A*B*!R)+(!A*!B*R)+(!A*B*R)+(A*B*R)
NORMALd (!A+B+!R)
Error!
Input the source formula:
A#B
Here!
4countTerms
NORMALc: (A*!B)+(!A*B)
NORMALd (A+B)*(!A+!B)
Error!
Input the source formula:
stack<char> stk;
bool isVar(char ch)const;
void addMin(int minterm);
void addMax(int maxterm);
bool compute(int minterm);
void getInversePoland();
int countTerms(int n);
void assign(int minterm);
stack<bool> boolStk;
public:
formulaBase();
formulaBase(const formulaBase& rhs);
~formulaBase();
void getSource();
cout<<"Invalid input !"
"Operate again:"<<endl;
cin>>sourceFormula;*/
}
void formulaBase::getInversePoland()
{
char temp,temp1;
for(int i=0;sourceFormula[i]!='