Personel Information

BSc: Physics Department, Middle East Technical University (METU), Ankara, Turkey
MSc: Physics Department, METU
PhD: Qualified, Physics Department, METU


Monday, July 11, 2016

FACTORIAL


## Function that calculates the factorial of a number
## Usage : f=factorial(n)
function f=factorial(n)
## Initialize the output
f=1;
## Check whether the input is correct
if ( (n<0) || (rem(n,1)~=0) )
printf("n cannot be a negative number. Exiting...\n");
return
endif
for num=1:n
f*=num;
endfor
endfunction

No comments:

Post a Comment