R Homework 1

Question 1

x <- 12
y <- 1
while (x >= 1)  {
  y = x * y
  x = x-1
if (x == 1)  {
  print (y)
             }
             
}
## [1] 479001600

Question 2

by5.vector <- seq(20, 50, by=5)
print (by5.vector)
## [1] 20 25 30 35 40 45 50

Question 3

quadratic <- function(a,b,c) {
  root1 <- (-b + sqrt((b*b)-4*a*c))/(2*a)
  root2 <- (-b - sqrt((b*b)-4*a*c))/(2*a)

  solutions <- c(root1,root2)
  
  return (solutions)
}

quadratic (3,1,-10)
## [1]  1.666667 -2.000000