This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

# 1. Write a Loop that calculates 12-factorial
# for Loop
factorial<-function(x){
  y<-1
  for(i in 1:x) {
    y<-y*((1:x)[i])
  }
  return(y) 
}

factorial(12)
## [1] 479001600
# 2. 

vector1 <- c( 20,25,30,35,40,45,50)


#

# Constructing Quadratic Formula
factorial <- function(a,b,c){
  if(formula(a,b,c) > 0){ 
    x_1 = (-b+sqrt(formula(a,b,c)))/(2*a)
    x_2 = (-b-sqrt(formula(a,b,c)))/(2*a)
    formula = c(x_1,x_2)
  }
  else if(formula(a,b,c) == 0){ 
    x = -b/(2*a)
  }
  else {"Root is missing"} 
}

# The equation
formula<-function(a,b,c){
  b^2-4*a*c
}

answer3 <- factorial(1,-4,1)
answer3
## [1] 3.7320508 0.2679492