I l@ve RuBoard Previous Section Next Section

8.4 Programming Exercises

Exercise 8-1: Print a checkerboard (8-by-8 grid). Each square should be 5-by-3 characters wide. A 2-by-2 example follows:

+-----+-----+ 
|     |     | 
|     |     | 
|     |     | 
+-----+-----+ 
|     |     | 
|     |     | 
|     |     | 
+-----+-----+ 

Exercise 8-2: The total resistance of n resistors in parallel is:

1/R = 1/R1 + 1/R2 + 1/R3 + ... + 1/Rn

Suppose we have a network of two resistors with the values 400figs/U03A9.gif and 200figs/U03A9.gif. Our equation would be:

1/R = 1/R1 + 1/R2

Substituting in the value of the resistors we get:

1/R = 1/400 + 1/200

1/R = 3/400

R = 400/3

So the total resistance of our two-resistor network is 133.3figs/U03A9.gif.

Write a program to compute the total resistance for any number of parallel resistors.

Exercise 8-3: Write a program to average n numbers.

Exercise 8-4: Write a program to print out the multiplication table.

Exercise 8-5: Write a program that reads a character and prints out whether it is a vowel or a consonant.

Exercise 8-6: Write a program that converts numbers to words. Example: 895 results in "eight nine five."

Exercise 8-7: The number 85 is said "eighty-five," not "eight five." Modify the previous program to handle the numbers 0-100 so all numbers come out as we really say them. For example, 13 is "thirteen," and 100 is "one hundred."

    I l@ve RuBoard Previous Section Next Section