CSE 131 / 501N (Fall 2013)
Recitation Questions

Some of the questions may involve more time than you have in lab. The idea is to stretch some on these problems, so that you will find the quiz and exam questions easier to tackle. The quiz and associated exam problems will resemble the questions you see here, so work to master these and you should have no problem on the quiz or exam.

Where there are multiple exercises within a problem, choose one or two and leave the rest for homeowork on your own.

  1. Sedgewick 1.3.3 page 77
  2. Write a program that prints the average of 1000 random numbers
  3. Given four integers a, b, c, and d, write a program that determines if no two of the 4 integers have the same value.
  4. Sedgewick 1.3.32 Ramanujan's taxi: 1729 is the smallest integer that can be expressed as the sum of two cubes in two different ways. In other words, there are four distinct positive integers a, b, c, and d such that a3 + b3 = c3 + d3
  5. Sedgewick 1.3.40 Let's make a deal problem
  6. Sedgewick 1.3.27 Write a program that given a value N prints out an NxN two-dimensional checkerboard that alternates spaces with asterisks.
  7. Given a and b a positive integers, what does the following program compute for its ans variable?
      int y   = 0;
      int ans = 0;
      while (y != b) {
          ans = ans + a;
          y = y + 1;
  8. For each of the following problems, justify using a while or a for statement to solve the problem.
    Value while? for?
    Print values 1 through 100    
    Prompt the user for input until the supplied value is 0    
    Compute random values until one exceeds 0.5    
    Compute and print 100 random values