Homework for CSPS Bridge class - R

QUestion 1: Write a loop that calculates 12-factorial

question1 = as.numeric(c(12))
factorial = 1
 
{
for(i in 1:question1) {
factorial = factorial * i
}
print(factorial)
}
## [1] 479001600

Question 2: Show how to create a numeric vector that contains the sequence from 20 to 50 by 5.

question2 <- function(x){}
series <- 20:50
seq(20, 50, by = 5)
## [1] 20 25 30 35 40 45 50

Question 3: Create the function “factorial” that takes a trio of input numbers a, b, and c and solve the quadratic equation. The function should print as output the two solutions.

question3 <- function(a, b, c) 
 
 {
   sol=b^2-4*a*c
   m=ifelse (sol<0,complex(1,0,sqrt(abs(sol))),sqrt(sol))
   c((-b+m)/(2*a),(-b-m)/(2*a))
  }