Problem 1:
for(i in 1:12){
if(i==1){
x<-i
}else
{
x <- i*x
if(i==12){
print(x)}
}
}
Problem 2:
x <- c(4:10) *5
Problem 3:
factorial <- function(a,b,c)
{
disc <- b^2-4*a*c
if(disc<0)
## This is the discriminant, shows if the answer is imaginary or real. If 0, only one answer, will be listed
## twice by the else part of the if statement
{
Top1 <- complex(1,-b,sqrt(-disc))
Top2 <- complex(1,-b,-sqrt(-disc))
## Top for the top of the fraction. This is where we have the two answers originate, so Top1 and Top2
## I felt numerator was too long a variable name for this
}else
{
Top1 <- -b + sqrt(disc)
Top2 <- -b - sqrt(disc)
## Not imaginary, so just adding and subtracting
}
Full1 <- Top1/(2*a)
Full2 <- Top2/(2*a)
print("x =")
print(Full1)
print(Full2)
}