19 Answers

New AnswerDenise Yes, apparently I was too much focusing on the "BOTH" part that I focus only on expressions involving logical AND && operator. The option (c) is also correct because (given x = 3, y = 6) ... ! ( 3 % 3 || 6 % 3) same as ... ! ( 0 || 0) same as ... ! (0) So, did your choice came as true (by the testpaper)?

Ipang sadly i dont know,i couldnt find the answers online.Hopefully there wont be any such exercises at the next transfer exam.

I guess it's because the logical NOT operator ! has higher precedence over modulo %. I'd recommended to wrap the modulo operands in parentheses in order for them to get evaluated first before the result is passed to logical NOT operator e.g. !(x % y) Or ... (!(x % y) && !(x % c))

which one of the expression are true *ONLY* IF BOTH variables (x,y) are divisible by 3.(Therefore if one expression CAN be true with one variable divisible by 3 and the other one not,the expression isnt the answer we're looking for) a) x%3 && y%3 b) !x%3 && !y%3 c) !(x%3 || y%3) (answer chosen by me) d) x%3==0 || y%3==0 and b) is basically making me confused

Well, considering the question requires BOTH <x> and <y> to be fully divisible by 3, I guess I'd go with codemonkey here. Option (c) and (d) uses logical OR meaning either one. Option (a) uses logical AND, but it evaluates to true when NEITHER <x> and <y> was fully divisible by three. And still, I'd put parentheses around x % 3 and y % 3. But that's just me :D

codemonkey Ipang I used the variables: x=3,y=6 And after running the code with the 4 expressions(separated of course),the output for a) and b) was FALSE,whereas for c) it was TRUE. but if you have a=0,b=0 both b) and c) will have the output TRUE. *cries*

Ipang #include<iostream> using namespace std; int main(){ long long a,b; cin>>a>>b; if(a%3&&b%3){ cout<<"TRUE"<<" "; } else{ cout<<"FALSE"<<" "; } if(!a%3&&!b%3){ cout<<"TRUE"<<" "; } else{ cout<<"FALSE"<<" "; } if(!(a%3||b%3)){ cout<<"TRUE"<<" "; } else{ cout<<"FALSE"<<" "; } if(a%3==0||b%3==0){ cout<<"TRUE"<<" "; } else{ cout<<"FALSE"<<" "; } return 0; } Did i do anything wrong? I suck at boolean expressions T_T

codemonkey its from a testpaper that's for transferring to a different high school(my friend will most likely have to take it too,and i decided to look over the one from 2016-2017 and then i saw this exercise and i was like:π€π=Am I stupid or am I stupid)And i couldnt find the answer online. Maybe you can choose 2 expressions or more ,not only one,but it didnt say anything about that(or if the numbers are >0)