🔒 Closed RECURSIVE FUNCTION LOGIC! (Explain why 40320 is the factorial of 8)

Status
Not open for further replies.

R3g4z4k1

Established
R Programming
#4 recursion
fact<-1
funct_recurse <- function(num)
{
print(paste("num :",num,"fact :",fact))
fact = 1
if(num > 1)
{ fact <- num * funct_recurse(num - 1)
print(paste("Num : ",num))
print(paste("Fact : ",fact))
return(fact)
}
else
{ return(fact)
}
}
number <- as.numeric(readline(prompt="input a number:"))
factorial <- funct_recurse(number)
print(paste("factorial of ",number,"is",factorial))


Output:
1669925686043.webp
 
Status
Not open for further replies.

About this Thread

  • 0
    Replies
  • 739
    Views
  • 1
    Participants
Last reply from:
R3g4z4k1

Trending Topics

Online now

Members online
346
Guests online
1,322
Total visitors
1,668

Forum statistics

Threads
2,292,325
Posts
29,076,048
Members
1,210,284
Latest member
cio
Back
Top