## CS 1401, Quiz #4

Date: Monday, September 25, 2006
Name: ____________________________________________________________
Class section (9:30 am or 11:30 am): _______________________________

1. How did the invention of logarithms help computing?

```
Logarithms made computations easier because they enabled to reduce
multiplication to an easier operation - addition. The use of
logarithms in computing is based on the fact that log(a*b) = log(a)
+ log(b). So, to compute a*b, we can do the following:

1) find log(a) and log(b),

2) add these two logarithms, thus computing s = log(a)+ log(b); and

3) find a number whose logarithm is equal to this sum s.

This number will be exactly a*b.

This idea formed the base of a slide rule, which for several
centuries was the main computational tool of engineers.

```
2. For each of the following topics, write "yes" or "no" depending on whether this topic is covered in Chapter 5, the chapter that you were supposed to read before the class:

while loops yes

arrays no

for loops yes

Graphical User Interfaces no

3. Suppose that we have three numbers n1, n2, and n3. Write down a code that assigns, to the variable largest, the largest of these three numbers. Hint: no need to read anything or print anything; assume that the variables n1, n2, and n3 already contain the numbers.

```if (n1 >= n2 && n1 >= n3)
largest = n1;
else if (n2 >= n1 && n2 >= n3)
largest = n2;
else
largest = n3;
```