/SCS2204Tutorial05

Functional Programming using Scala Tutorial 5

Primary LanguageScala

SCS2204Tutorial05

Functional Programming using Scala Tutorial 5

  1. Write a recursive function prime(n) that returns true for a prime number and false for the other? For example prime(5) should return true and prime(8) should return false.
  2. Write a recursive function primeSeq(n) that prints all prime number which less than n? For example prime(10) should print 2,3,5, and 7 on the terminal.
  3. Write a recursive function returns the addition of numbers from1 to n? For example sum(5) should print 15
  4. Write a recursive function to determine even and odd numbers?
  5. Write a recursive function to get the addition of all even numbers less than given n.
  6. The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, . . . Each subsequent number is the sum of the previous two. Write a recursive function print fist n Fibonacci numbers for given n