Created
July 3, 2021 01:24
-
-
Save jailsonsf/ada94da6c2e107917e3be57dde5a8d7b to your computer and use it in GitHub Desktop.
Fibonacci in kotlin
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
fun main(args: Array<String>) { | |
val n = readLine()!!.toInt() | |
var sum : Int | |
var t1: Int = 0 | |
var t2: Int = 1 | |
for (i in 1..(n-1)) { | |
print("${t1} ") | |
sum = t1 + t2 | |
t1 = t2 | |
t2 = sum | |
} | |
print("$t1") | |
println() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment