Write a loop that calculates 12-factorial
f=12
k=1
repeat{
if(f>0){
k=k*(f)
f=f-1
} else if(f==0){
break
}
}
print(k)
## [1] 479001600
Show how to create a numeric vector that contains the sequence from 20 to 50 by 5
numvec=seq(20,50,5)
print(numvec)
## [1] 20 25 30 35 40 45 50
Create the function “factorial” 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.
Quadratic Form for \(ax^2+bx+c=0\)
\[x=\frac{-b \pm \sqrt(b^2-4ac)}{2a}\]
I added default values for numbers that I know works.
factorial = function(a=1, b=3, c=-4){
x1= (-b+sqrt(b^2-4*a*c))/(2*a)
x2= (-b-sqrt(b^2-4*a*c))/(2*a)
print(c(x1,x2))
}
factorial(a=2,b=-4,c=-3)
## [1] 2.5811388 -0.5811388