Question 1 - Write a loop that calculates 12-factorial

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

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

seq(20,50,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.

factorial <- function(a,b,c){
  discrim <- b^2-4*a*c
  ifelse(discrim < 0, 
         discrim <- complex(r=0,i=sqrt(-1*discrim)),
         discrim <- sqrt(discrim))
  print((-b + discrim)/(2*a))  
  if(discrim != 0)
    print((-b - discrim)/(2*a))
}

factorial(1,4,5) 
## [1] -2+1i
## [1] -2-1i
factorial(2,4,-4)
## [1] 0.7320508
## [1] -2.732051
factorial(1,-6,9)
## [1] 3