#Assigning y a starting value of 1 because the loop starts at 1
y<-1
#Creating the loop and then as factorial formula
for(i in 1:12){
y <-y*((1:12)[i])
print(y)
}
## [1] 1
## [1] 2
## [1] 6
## [1] 24
## [1] 120
## [1] 720
## [1] 5040
## [1] 40320
## [1] 362880
## [1] 3628800
## [1] 39916800
## [1] 479001600
#The vector below of 20 to 50
y<-c(20:50)
#I wanted to print out the results of the vector based on the placement in the vector.
print(y[c(1,6,11,16,21,26,31)])
## [1] 20 25 30 35 40 45 50
#Searching Google I found this function that produces the same result
x<-seq(20,50,by=5)
print(x)
## [1] 20 25 30 35 40 45 50
#ABC inputs
a<- readline(prompt="Enter a number for a: ")
## Enter a number for a:
b<- readline(prompt="Enter a number for b: ")
## Enter a number for b:
c<- readline(prompt="Enter a number for c: ")
## Enter a number for c:
#Convert to int
a<-as.integer(a)
b<-as.integer(b)
c<-as.integer(c)
#Discriminant
d<-b^2-4*a*c
d<-as.integer(d)
#Quadratic formula
s1<-(-b + sqrt(d))/(2*a)
s2<-(-b - sqrt(d))/(2*a)
print(s1)
## [1] NA
print(s2)
## [1] NA