Exercises

September 13 - September 15, 2006

  1. Determine the results of the following statements given a=6 b=9 c=12 d=-7 e=0 f=12:
    1. print a > d
    2. print c <= f
    3. print d > e
    4. print c = f
    5. print c == f
    6. print c > b and e > f
    7. print c > b or e > f
    8. print a or e
    9. print e and a
  2. Write an if statement that compares two integer variables x and y and prints the largest. For example, your program would print “X is larger than Y” or “Y is larger than X”.
  3. Modify your program above so that it compares three integers x, y, and z and prints the largest.
  4. Write a function that takes as input a year and returns true if the year is a leap year and false otherwise. A year is a leap year if it is divisible by four, except that any year divisible by 100 is a leap year only if it is divisible by 400 as well. -Problem Solving and Program Design in C Hanly and Koffman

Sami Rollins