Input
Output
Sample Input
Sample Output
Test Yourself
Problem Statement
In a previous lesson on recursion, we implemented the recursive factorial function. You need to design a tail-recursive version of the factorial function given below.
xxxxxxxxxx
def factorial(x: Int) : Int = {
if(x == 1)
1
else
x * factorial(x-1)
}
// Driver Code
print(factorial(3))