1) Write a loop that calculates 12-factorial

fact <- function(num) {
  if(num<=0) {
    return("insert positive numbers greater than 0.")
  }else if(num>0 & num<=1) {
      return(1)}else{return(num*fact(num-1))
  }
}
fact(12)
## [1] 479001600

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

v <- seq(20,50,5)
v
## [1] 20 25 30 35 40 45 50

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.

fact_quad_eqt <- function(a,b,c){
  if(discr(a,b,c)==0) {
    return(list(x=-b/(2*a)))
  } else if(discr(a,b,c)>0) {
      return(list(x1=(-b+sqrt(discr(a,b,c)))/(2*a), x2=(-b-sqrt(discr(a,b,c)))/(2*a)))
  } else {
      return("no roots.")
  }
}
discr <- function(a,b,c) {
  return((b*b)-(4*a*c))
}
 ## x^2-4x+3=0
fact_quad_eqt(1,-4,3)
## $x1
## [1] 3
## 
## $x2
## [1] 1
## 2x^2-4x+2=0
fact_quad_eqt(2,-4,2)
## $x
## [1] 1
## 4x^2-4x+3=0
fact_quad_eqt(4,-4,3)
## [1] "no roots."