Courses‎ > ‎Introduction to Computer Science 1‎ > ‎Konstantinovich‎ > ‎ML1 9/2012‎ > ‎labs‎ > ‎

Lab 01

posted Sep 20, 2012, 6:10 AM by Samuel Konstantinovich   [ updated Dec 21, 2012, 5:23 AM ]

  • Write the following functions:
    • (getOnesDigit x)   →  returns the ones digit of an integer x
    • (getTensDigit x)   →  returns the tens digit of an integer x
    • (getHundredsDigit x) → returns the hundreds digit of an integer x
      • How many mathematical ways can you extract the tens place?
  • What is a generic way to extract the 10^nth place of a number? e.g. extract the 1000’s place? 10,000th place? Think about how the tens and hundreds can be written almost the same way BEFORE trying the last part.
  • Write a function:
    • (getPlace x column)
    • Assume x is an integer, and  column is a power of 10 like 100, 1000 etc. This function extracts the digit of x at that place, or 0 if the column doesn’t exist. Examples:
      • (getPlace 552834 1000) → 2
      • (getPlace 552834 100) → 8
      • (getPlace 2834 10000000) → 0

Comments