Ok...I've started learning perl on my own, out of interest basically.
I'd like to know how do i write a programme that will calculate the sum: 1!+2!+3!+4!
I'd appreciate the help of experienced perl programmers. It's perl not pearl.
to add ! stands for factorial..basically the sum of 1,2,3 and 4 factorials.
I've been reading up on books and searching the net and I can't seem to find any answers
I didn't learn Perl, but in general, you can write a recursive function to calculate factorials, and simply call it in a statement.
Example (in PHP):
function f($x) {
if ($x > 0) {
return $x * f($x - 1);
} else {
return 1;
}
}
$answer = f(1) + f(2) + f(3) + f(4);