In this program, You will learn how to find the factorial of a number in R.
Example: How to find the factorial of a number in R
1 2 3 4 5 6 7 8 9 10 11 12 |
{ x <- as.integer(readline(prompt = "Enter a number :")) f = 1 for (i in 1:x) { f = f * i } print(paste("Factorial is :", f)) } |
Output:
1 2 3 4 |
Enter a number :5 [1] "Factorial is : 120" |