Question 1: Write a loop that calculates 12-factorial

factorial.num = 1
for(i in 1:12)
{
  print(i)
  factorial.num <- factorial.num * i
}
## [1] 1
## [1] 2
## [1] 3
## [1] 4
## [1] 5
## [1] 6
## [1] 7
## [1] 8
## [1] 9
## [1] 10
## [1] 11
## [1] 12
print(factorial.num)
## [1] 479001600

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

v_seq_by_5 <- seq(from=20, to=50, by = 5)
v_seq_by_5
## [1] 20 25 30 35 40 45 50
class(v_seq_by_5)
## [1] "numeric"

Question 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)
{
 plus.quad.eq <- (-b + sqrt(b^2 - (4 * a * c)))/ 2 * a
 minus.quad.eq <- (-b - sqrt(b^2 - (4 * a * c)))/ 2 * a
 sprintf("Plus result: %s and Minus result: %s", plus.quad.eq, minus.quad.eq)
}

a <- 1
b <- 5
c <- 6

quadratic(a, b, c)
## [1] "Plus result: -2 and Minus result: -3"