function f=myfactorial(N)
% Calculates factorial of the input. N!=N*(N-1)!
% Input must be an integer larger or equal to zero.

	if ( N < 0 ) % ALWAYS sanitize the input !!!
		error('wrong input, input must be >= 0');
	end
	if ( N ~= floor(N) )
		error('input is not an integer number');
	end
% Once input is good we can calculate the factorial
	if ( N==0 )
		f=1; return; % return stops the evaluation
	end
	f=N*myfactorial(N-1);
end
