O'Reilly logo

C Primer Plus, Fourth Edition by Stephen Prata

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 7

1: Determine which expressions are true and which are false.
  1. 100 > 3 && 'a'>'c'

  2. 100 > 3 || 'a'>'c'

  3. !(100>3)

A1: True: b.
2: Construct an expression to express the following conditions:
  1. number is equal to or greater than 1 but smaller than 9.

  2. ch is not a q or a k character.

  3. number is between 1 and 9 but is not a 5.

  4. number is not between 1 and 9.

A2:
  1. number >= 1 && number < 9

  2. ch != 'q' && ch != 'k'

  3. (number >= 1 && number <= 9) && number != 5

  4. !( (number >= 1 && number <= 9) or else number < 1 || number > 9

3: The following program has unnecessarily complex relational expressions as well as some outright errors. Simplify and correct it.
 #include <stdio.h> int main(void) /* 1 */ { /* 2 */ int weight, height; /* weight in lbs, height in inches */ /* ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required