Exercise7Chp5Solut

Exercise7Chp5Solut - ! (a && c)...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Name________________________ CSE182 1 CSE 182 Exercise #7 (Chapter 5) 1. Evaluate each of the following logical expressions. That is, determine whether they evaluate to true or false . Assume that x is 1. 1) (true) && (3 > 4) false 2) !( x > 0) && ( x > 0) false 3) ( x > 0) || ( x < 0) true 4) ( x != 0) || ( x = = 0) true 5) ( x >= 0) || ( x < 0) true 6) ( x != 1) = = ! ( x = =1) true 2. Assume that x and y are int type. Which of the following are valid C# expressions? 1) x > y > 0 invalid, should write like (x > y) && (y > 0) 2) x = y && y 3) x /= y valid. 4) x AND y invalid, can’t use word AND to form a C# Boolean expression 5) ( x != 0) || ( y = 0) invlaid, right hand side of || should be (y = = 0) 3 . A truth table shows, for the various true or false values of boolean variables, what the result of a boolean condition is. Fill in the following truth table by showing whether ! (a && b) | |
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ! (a &amp;&amp; c) evaluates True or False for different values of a, b, and c. Assume that a, b and c are boolean variables. a b c ! ( a &amp;&amp; b ) | | ! ( a &amp;&amp; c ) ----------------------------------------------------------------- false false false true false false true true false true false true false true true true true false false true true false true true true true false true true true true false 4. Suppose that x is 1, determine whether the following expression evaluates to true or false . What is x after the evaluation of the following expression? 1) ( x &gt; 1) &amp;&amp; ( x ++ &gt; 1) false, x = 1 2) ( x &gt; 1) &amp; ( x ++ &gt; 1) false, x = 2 3) ( x &gt;= 1) &amp;&amp; ( x ++ &gt; 1) false, x = 2 4) ( x &gt;= 1) &amp;&amp; ( ++ x &gt; 1) true, x = 2 5) ( x &gt; 1) | ( ++ x &gt; 1) true, x = 2 6) ( x &gt; 1) | | ( ++ x &gt; 1) true, x = 2...
View Full Document

Ask a homework question - tutors are online