Chapter 2 Exercise Set 2


Write a function, double, that takes an argument, n, and returns twice the value of n.

compare(a, b)

Write a compare(a, b) function that returns 1 if a > b, 0 if a == b, and -1 if a < b.


Write a function isEven that takes an integer, n, as an argument and returns true if n is even and false otherwise.

isFactor(f, n)

Write a function isFactor that takes two integers, f and n, as arguments and returns true if f is a factor of n and false otherwise.

f2c(t) and c2f(t)

Write a function f2c that takes a tempurature, t in Fahrenheit as an argument and returns the equivalent temperature in Celsius. Then write a function c2f that does the opposite conversion.


Write an isDigit function that takes a character, ch, as an argument and returns true if ch is a digit (a character between '0' and '9') and false otherwise.