# R Week 1 Assignment - Jagdish Chhabria

# 1.Write a loop that calculates 12-factorial

# Initialize the variable
factorial = 1

# Loop from 12 to 1, multiplying each iteration with the product from the previous iteration
for (i in 12:1)
{factorial=factorial*i}

# print the variable showing the final product
print(factorial)
## [1] 479001600
# 2. Show how to create a numeric vector that contains the sequence from 20 to 50 by 5.

numvec<-seq(20,50, by=5)
numvec
## [1] 20 25 30 35 40 45 50
#3. 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

factorial<-function(a, b, c)
{
  x1=(-b+(b^2 - 4*a*c)^(1/2))/(2*a)
  x2=(-b-(b^2 - 4*a*c)^(1/2))/(2*a)
  print(x1)
  print(x2)
 }
factorial(2, 7, 4)
## [1] -0.7192236
## [1] -2.780776