Changes

Jump to: navigation, search

GPU621/Chapel

256 bytes added, 22:05, 29 November 2022
Overloading
if x < 0 then
halt("factorial -- Sorry, this is not the gamma procedure!");
 
return if x == 0 then 1 else x * factorial(x-1);
}
We can overload the factorial function to accept the 32-bit integers.
proc factorial(x: int(32)) : int(32)
{
if x < 1 then
halt("factorial -- Invalid operand.");
if x < 3 then return x;
return x * (x-1) * factorial(x-2);
}
= Reference =
73
edits

Navigation menu