Scheme Exercises

back to exercise list       previous     next

Group:     Exercise: 18/48 

getNthDigit:  Retrieve the nth digit of a number

Challenge problem: Create a function called "getNthDigit" which will be given two arguments: a multi-digit positive number (like, 473289, for instance) and a digit-position, (like 3, for instance) and in this case, will return the 3rd digit (from the right) of the number 473289, which is: 2.
Examples:
(getNthDigit 45227 1) -> 7
(getNthDigit 15226 4) -> 5
(getNthDigit 25 3) -> 0