🔒 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
  • 760
    Views
  • 1
    Participants
Last reply from:
R3g4z4k1

Online now

Members online
1,085
Guests online
5,350
Total visitors
6,435

Forum statistics

Threads
2,348,907
Posts
29,359,630
Members
1,092,783
Latest member
seraphem22
Back
Top