C++ 写出正确的逻辑表达式
当最多两个数字A、B、C为非正数时,编写为真的逻辑表达式。你能回答这个问题吗 老师说答案是肯定的 !A=<0&&B=<0&&c0 | | B>0 | | C>0C++ 写出正确的逻辑表达式,c++,c++11,c++14,C++,C++11,C++14,当最多两个数字A、B、C为非正数时,编写为真的逻辑表达式。你能回答这个问题吗 老师说答案是肯定的 !A=0 我还是不明白她的答案,你能帮我吗?现在,问题表明A、B、C中最多有2个是非肯定的。这意味着包含3个数字并返回true的条件是 1. 在这里,同样的理由成立,其中至少有一个会返回为真。您的老师应用了德摩根定律,该定律说: not (A or B) = not A and not B; 及 查看工作代码的完整说明 #include <iostream> using names
我还是不明白她的答案,你能帮我吗?现在,问题表明A、B、C中最多有2个是非肯定的。这意味着包含3个数字并返回true的条件是 1.
在这里,同样的理由成立,其中至少有一个会返回为真。您的老师应用了德摩根定律,该定律说:
not (A or B) = not A and not B;
及
查看工作代码的完整说明
#include <iostream>
using namespace std;
//Function for logic
bool myFun(int a,int b,int c)
{
bool conditionFirst=!(a <= 0 && b <= 0 && c <= 0);
bool condintionSecond=(a > 0 || b > 0 || c > 0);
if(conditionFirst==true && condintionSecond==true)
return true;
else
return false;
}
int main() {
int a,b,c;
cin>>a>>b>>c;
if(myFun(a,b,c))
cout<<"True";
else
cout<<"False";
}
你为什么不问问她呢?当最多两个数字A、B、C是非正数时,写出正确的逻辑表达式当至少一个数大于0时,写出逻辑表达式。如果表达式中的三个数最多为非正,如果表达式为真,则唯一的方法是如果所有三个都是负值。A= 0是无效的C++。也许,A=< 0不是有效的C++。如果这些表达写得好的话
not (A or B) = not A and not B;
not (A and B) = not A or not B
#include <iostream>
using namespace std;
//Function for logic
bool myFun(int a,int b,int c)
{
bool conditionFirst=!(a <= 0 && b <= 0 && c <= 0);
bool condintionSecond=(a > 0 || b > 0 || c > 0);
if(conditionFirst==true && condintionSecond==true)
return true;
else
return false;
}
int main() {
int a,b,c;
cin>>a>>b>>c;
if(myFun(a,b,c))
cout<<"True";
else
cout<<"False";
}