'Please create the following exercises in .rmd format, publish to rpub and submit both the .rmd file and
the rpub link.
1. Write a loop that calculates 12-factorial
2. Show how to create a numeric vector that contains the sequence from 20 to 50 by 5.
3. Create the function "quadratic" 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.'
## [1] "Please create the following exercises in .rmd format, publish to rpub and submit both the .rmd file and\nthe rpub link.\n1. Write a loop that calculates 12-factorial\n2. Show how to create a numeric vector that contains the sequence from 20 to 50 by 5.\n3. Create the function \"quadratic\" that takes a trio of input numbers a, b, and c and solve the quadratic\nequation. The function should print as output the two solutions."
# 1
factorial = 1
for (i in 1:12)
{
factorial = factorial*i
}
print(paste("12! equals...", factorial))
## [1] "12! equals... 479001600"
# 2
x0 = 20
seq(x0, 50, 5)
## [1] 20 25 30 35 40 45 50
# 3
quad_form <- function(a,b,c)
{
disc <- sqrt(b^2 - (4*a*c))
first_root <- (b*-1 + disc)/(2*a)
second_root <- (b*-1 - disc)/(2*a)
print(first_root)
print(second_root)
}
quad_form(1,2,3)
## Warning in sqrt(b^2 - (4 * a * c)): NaNs produced
## [1] NaN
## [1] NaN