Wednesday, 24 October 2012

Week 7: If-else Statements and GCD

This week, I've learned about the if-else statements and the build-in function GCD.

For the conditional statement, I've tried to define some with it.
For example, defining a number greater than 500 as big,

(define (bigger-number n)
  (cond
    [(> n 500) "big"]
    [else "Not too big"])) 

(check-expect (bigger-number 30) Not too big)
(check-expect (bigger-number 555) big)



The greatest common divisor (GCD) of two non-negative integers (whole numbers) is a non-negative integer that
  1. divides both numbers, and
  2. is the largest non-negative number that does so.

For the GCD funtion, here are some examples,

(GCD 2 10)
>2
(GCD 100 10)
>10
It is so much easier and convenient when you can find the GCD on the computer.


No comments:

Post a Comment