Home > COMP20005, education, programming > COMP20005 workshop 3

COMP20005 workshop 3

In this workshop, you will solve problems that require you to use loops. You can use the for loop or the while loop. There’s another type of loop called a do loop, but you could transform a do loop into a while loop. Whenever you have a for loop, think about how to transform it into a while loop; and vice versa.

The assigned exercises for this workshop are exercises 4.1, 4.2, 4.5, and 4.9. Be careful with exercises 4.1(f,g). These exercises illustrate two errors in loops: one is a loop with an empty body and the other is an infinite loop. Exercise 4.2 asks you to think about how to transform a do loop into a for loop. This should be easy if you know how to transform a while loop into a for loop. In exercise 4.5, you need to read in a sequence of positive integers and plot the integers as a histogram. Think about how you would handle the case of an integer with one digit and the case of an integer with multiple digits. Exercise 4.9 is a little bit challenging and requires you to know a little bit about prime numbers. The basic idea of the exercise is that your program should read in a positive integer and find the next prime number after the integer. All prime numbers greater than 2 are odd, so you can limit your search to only the odd integers.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: