Welcome to BigData School that can get you hired on Small startups or big Product based companies.Are you tired of 30-40 hours of theoritical bigdata courses in the market. Welcome to 240+ hours of Bigdata training. Just subscribe to our popup to get access to our 80+hours of course absolutely free.Try them out and you can join our further course once you are happy with our Demos.

fibonacci Number

Big Data    On Thursday 22nd of June 2017 12:10:06 PM By Suraz Ghimire
Write a program to find out fibonacci Series.
Input: 10
Output: first 10 fibonacci number

package sorting.searching

object FibonacciSeries {

def fibonacci(num: Int)={
// 0 1 1 2 3 5
var i=0
var j=1
print(s"$i $j ")
var count=0

while(count<num-2){ //As we have already printed 2 numbers
val k=j
j=i+j
i=k
print(s"$j ")
count+=1
}

}

def main(args: Array[String]): Unit = {
fibonacci(10)
}
}

output:
0 1 1 2 3 5 8 13 21 34 

About Author

Suraz Ghimire