Hi, this is a multiple choice question from my AP CS review book. I can't seem to figure out the right answer even after looking at the answer.

Which of the following will evaluate to true only if boolean expression A, B, and C are all false?

A) !A && !(B && !C)
B) !A || !B || !C
C) !(A || B || C)
D) !(A && B && C)
E) !A || !(B || !C)

Recommended Answers

All 2 Replies

You have 8 situations. So we check them all

false, false, false - A, B, C, D, E are TRUE
false, false, true - A, B, D, E are TRUE
false, true, false - B, D, E are TRUE
false, true, true - A, B, D, E are TRUE
true, false, false - B, D, E are TRUE
true, false, true - B, D, E are TRUE
true, true, false - B,D are TRUE
true, true, true - All FALSE

So given those, answer (C) is only true when all of them are false.

Answer C is correct, but it can also be expressed like this

!(A || B || C) == (!A && !B && !C)

Why? Well you could generate a set of truth tables (ever take formal logic?), or just think about it.

if (A is true) or (B is true) or (C is true), then (A or B or C) is true.
Apply negation operator NOT to (A or B or C) is saying "if NOT (A or B or C), then results is TRUE only if they ALL are FALSE".

More confused yet? :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.