This is the first part of the homework where I calculate the
factorial of 12
partA <- function(x) {
numb <- 1
for(i in 1:x) {
numb <- numb * i
}
return(numb)
}
partA(12)
## [1] 479001600
This is the second part where I created a vector that contains a
sequence from 20 to 50 by 5
sequence <- seq(from = 20, to = 50, by = 5)
sequence
## [1] 20 25 30 35 40 45 50
This is the third part where I created a function that solved the
quadratic equation
quad <- function(a,b,c){
d=b^2-(4*a*c)
if (d < 0){
cat("Error: no real solution")
}else if(d==0){
solution <- -b / (2*a)
cat("One real solution: ", solution)
} else{
solution1 <- (-b+sqrt(d)) / (2*a)
solution2= (-b-sqrt(d)) / (2*a)
cat("First solution: ",solution1,"\n","Second solution: ", solution2)
}
}
quad(1,2,1)
## One real solution: -1
quad(1,6,5)
## First solution: -1
## Second solution: -5
quad(1,1,1)
## Error: no real solution