Learn-dsa..in 30 days!



























CC-5 : Find factorial of number.

Description:

Given an input number, find its factorial.

Test cases and expected outputs:

Input Parameters Expected outputs
Number: 6 Factorial: 720
Number: 7 Factorial: 5040

Pseudocode:

DecimalToBinary(num):

The number to be checked is received as input parameter.
If num==0, return 1; (base case).
Recursively call factorialOfNum() with parameter num-1 and multiply return value fromrecursive call with num and return the calculated value..

Code:

public int factorialOfNumber(int num){
	if (num == 0) {
		return 1;
	}
	return num * factorialOfNumber(num-1);	
}


Click here to download and run code and test cases !