cara menggunakan rekursi di r
mySum <- function(a){
if (a == 0)
return(0)
return(a + mySum(a-1))
}
mySum(0)
Rocku0
mySum <- function(a){
if (a == 0)
return(0)
return(a + mySum(a-1))
}
mySum(0)
> recursive.factorial(0)
[1] 1
> recursive.factorial(5)
[1] 120
> recursive.factorial(7)
[1] 5040
# Recursive function to find factorial
recursive.factorial <- function(x) {
if (x == 0) return (1)
else return (x * recursive.factorial(x-1))
}