Created
March 27, 2013 04:02
-
-
Save a-suenami/5251539 to your computer and use it in GitHub Desktop.
scalaでフィボナッチ数列。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Fib extends App { | |
def fib(n: Int): Int = { | |
if (n < 2) { return n } else { return fib(n-1) + fib(n-2) } | |
} | |
Console.println("fib(1) = " + fib(1)); | |
Console.println("fib(2) = " + fib(2)); | |
Console.println("fib(3) = " + fib(3)); | |
Console.println("fib(4) = " + fib(4)); | |
Console.println("fib(5) = " + fib(5)); | |
Console.println("fib(6) = " + fib(6)); | |
Console.println("fib(7) = " + fib(7)); | |
Console.println("fib(8) = " + fib(8)); | |
Console.println("fib(9) = " + fib(9)); | |
Console.println("fib(10) = " + fib(10)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment