Skip to content

Commit

Permalink
Create Factorial.R
Browse files Browse the repository at this point in the history
  • Loading branch information
StepfenShawn authored May 5, 2021
1 parent fb8f46d commit 9cca0af
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions maths/Factorial.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Fact <- function(n){
if(n < 0) print("warning: your input is wrong!")
else if(n == 0 | n == 1) print(1)
else {
s <- numeric()
s[1] = 1
for(i in 2 : n){
s[i] = i * s[i - 1]
}
return(s[n])
}
}

Fact(5)
Fact(6)

0 comments on commit 9cca0af

Please sign in to comment.