R Markdown

#1 Write a loop that calculates 12-factorial

inFact <-1 for (x in 1:12){ if(x==1) inFact <- 1 else { inFact <- inFact * x } cat(x, “!:”, inFact, “”) }

#2Show how to create a numeric vector that contains the sequence from 20 to 50 by 5

n <- seq(20,50,5) as.numer

#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

a = readline(“Enter a value of a:”) b = readline(“Enter a value of b:”) c = readline(“Enter a value of c:”)

a=as.integer(a); b=as.integer(b); c=as.integer(c);

root <- function(a,b,c) { if(del(a,b,c) > 0) { r1=(-b+sqrt(del(a,b,c)))/(2a) r2=(-b-sqrt(del(a,b,c)))/(2a) root=c(r1,r2) } else if(del(a,b,c)==0) { r=-b/(2a) } else{“There are no real roots.”} } del<-function(a,b,c) { b^2-4a*c } roots=root(a,b,c) print(roots)