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

Online now

Members online
336
Guests online
3,328
Total visitors
3,664

Forum statistics

Threads
2,277,873
Posts
28,979,379
Members
1,229,129
Latest member
bornik69
Back
Top