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]!='