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

Trending Topics

Online now

Members online
1,228
Guests online
3,075
Total visitors
4,303

Forum statistics

Threads
2,337,842
Posts
29,300,251
Members
1,125,815
Latest member
freak123
Back
Top