A president and a treasurer are to be chosen from a student club consisting of 50 people. We can find the number of different choices of officers when there are no restrictions as 50P2. How would you program this into R

Respuesta :

Answer:

> factorial()

Input a number to find factorial : 50

[1] " The factorial result is  50 is 3.04140932017134e+64"

> factorial()

Input a number to find factorial : 48

[1] " The factorial result is  48 is 1.24139155925361e+61"

and we divide both numbers and we got 2450

Step-by-step explanation:

We know that in permutations the order matters, and the general formula for [tex] nPx [/tex] is given by:

[tex] nPx = \frac{n!}{(n-x)!}[/tex]

So we need to create a function for the factorial function in R like this:

factorial <- function(){

# The function only accepts an integer

number = as.integer( readline(" Input a number to find factorial : "))

fact = 1

# If the number is negative or 0

if(number < 0) {

print(" The number is negative the factorial does not exist. ")

} else if(number == 0) {

print(" The factorial result is 1 ")

} else {

for( i in 1:number) {

fact = fact * i

}

print(paste(" The factorial result is ", number ,"is", fact ))

}

}

And we can find the expression like this:

> factorial()

Input a number to find factorial : 50

[1] " The factorial result is  50 is 3.04140932017134e+64"

> factorial()

Input a number to find factorial : 48

[1] " The factorial result is  48 is 1.24139155925361e+61"

and we divide both numbers and we got 2450

ACCESS MORE
ACCESS MORE
ACCESS MORE
ACCESS MORE