Question 1
fact <- 1
for (x in 1:12)
{
fact = fact*x
}
fact
## [1] 479001600
Question 2
vec <- seq(20,50, by = 5)
vec
## [1] 20 25 30 35 40 45 50
Question 3
factorial <- function(a,b,c){
if (a == 0)
{
print("That equation isn't quadratic!")
}else
{
if (b^2 - 4*a*c < 0)
{
cat("Check your inputs\nOnly Imaginary solutions exist")
}else if (b^2 - 4*a*c > 0)
{
sol1 = (-b + sqrt(b^2 - 4*a*c))/(2*a)
sol2 = (-b - sqrt(b^2 - 4*a*c))/(2*a)
sprintf("Solution 1: %s\ Solution 2: %s", sol1,sol2)
}else
{
sol = -b/(2*a)
sprintf("One solution exists: %s", sol)
}
}
}
factorial(2,9,1)
## [1] "Solution 1: -0.113999063670617 Solution 2: -4.38600093632938"