Write a function to calculate factorial of a number

Code: