Exercise7Chp5Solut

# Exercise7Chp5Solut - (a&& c evaluates True or False...

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

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) | |
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ! (a && 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 && b ) | | ! ( a && 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 > 1) && ( x ++ > 1) false, x = 1 2) ( x > 1) & ( x ++ > 1) false, x = 2 3) ( x >= 1) && ( x ++ > 1) false, x = 2 4) ( x >= 1) && ( ++ x > 1) true, x = 2 5) ( x > 1) | ( ++ x > 1) true, x = 2 6) ( x > 1) | | ( ++ x > 1) true, x = 2...
View Full Document

## This note was uploaded on 02/11/2010 for the course CSE CSE182 taught by Professor Feng during the Spring '10 term at ASU.

Ask a homework question - tutors are online