#1 A loop that calculates 12 factorial:

# assign the numbers used in 12 factorial as a vector to 'factorial'
factorial<-12:1

for (i in factorial)
{
  # if i is 12, skip
  if (i==12)
  {
    next
  }
  # multiply 12 (the first number in the vector) by each number in the vector (excluding 12)
  x=factorial[1]*i*(i-1)*(i-2)*(i-3)*(i-4)*(i-5)*(i-6)*(i-7)*(i-8)*(i-9)*(i-10)
  # show only the solution
  if (x>0)
  {
    v<-x[1]
    print(v)
  }
}
## [1] 479001600

#2 Creating a numeric vector that contains the sequence from 20 to 50 by 5.

# assign the vector that contains the sequence from 20 to 50 by 5 to nvector
nvector<-c(20,25,30,35,40,45,50)
# print the vector 
print(nvector)
## [1] 20 25 30 35 40 45 50
# show the class of the vector
class(nvector)
## [1] "numeric"

#3 Create the function “quad” 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.

solve.quad<-function(a,b,c)
{
  #first solution
  x1<- (-b+(b**2 - 4*a*c)**0.5)/(2*a)
  #second solution
  x2<- (-b-(b**2 - 4*a*c)**0.5)/(2*a)

  #print first solution
  names(x1)<-c("Solution 1: ")
  # if the solution is a complex number, print that it is a complex number
  # otherwise print solution
  {
    if (is.na(x1))
    {
      print("Solution 1 contains a complex number")
    } else
    {
      print(x1)
    }
  }
  
  # print second solution
  names(x2)<-c("Solution 2: ")
  # if the solution is a complex number, print that it is a complex number
  # otherwise print solution
  {
    if (is.na(x2))
    {
      print("Solution 2 contains a complex number")
    } else
    {
      print(x2)
    }
  }

}

solve.quad(1,2,1)
## Solution 1:  
##           -1 
## Solution 2:  
##           -1
solve.quad(1,6,5)
## Solution 1:  
##           -1 
## Solution 2:  
##           -5
solve.quad(1,1,1)
## [1] "Solution 1 contains a complex number"
## [1] "Solution 2 contains a complex number"