Exercise #1.

Write a loop that calculates 12-factorial.

result <- 1
for (i in 12:1){
  result <- result * i
}
result
## [1] 479001600

Exercise #2.

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

v <- (4:10)*5
v
## [1] 20 25 30 35 40 45 50

Exercise #3.

Create the function “quadratic” 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.

quadratic <- function(a,b,c){
  if (b^2 < 4*a*c){
    result <- "No real roots"
  }else{
    result <- c((-b + sqrt(b^2 - 4 * a * c))/(2 * a),(-b - sqrt(b^2 - 4 * a * c))/(2 * a))
  }
  return (result)
}

quadratic(a = 1, b = 2, c = 1)
## [1] -1 -1
quadratic(a = 1, b = 0, c = 25)
## [1] "No real roots"
quadratic(a = 3, b = 3, c = -6)
## [1]  1 -2