–> Function to calculate factorial of a number passed as arguement
get.factorial <- function(input.num = "0", ...)
{
if(is.integer(as.integer(input.num)) && input.num >= 1)
{
ret_fact<- 1
for (i in 1:input.num)
ret_fact <- ret_fact * i
}else
{
return ('Not a valid Number Passed !')
}
return ( ret_fact)
}
–> Get the factorial by passign the input value
get.factorial(12)
## [1] 479001600
–> Function to return a sequence
get.sequence_vector <- function(start, end, interval, ...)
{
return (seq(from=start, to=end, by= interval))
}
–> Get the numeric vector by passign the input value
get.sequence_vector(start=20, end=50, interval= 5)
## [1] 20 25 30 35 40 45 50
–> Function to solve the quadratic equation
quadratic <- function(a, b, c, ...)
{
x1 <- ( -(b) + sqrt((b ^ 2 ) - (4 * a * c)) ) / (2*a)
x2 <- ( -(b) - sqrt((b ^ 2 ) - (4 * a * c)) ) / (2*a)
sprintf ("x is equal to %s or %s", x1, x2)
}
–> Get the input 1
inp.a <- 10
inp.b <- 12
inp.c <- 2
quadratic(a = inp.a, b = inp.b, c = inp.c)
## [1] "x is equal to -0.2 or -1"
–> Get the input 2
inp.a <- 5
inp.b <- 6
inp.c <- 2
quadratic(a = inp.a, b = inp.b, c = inp.c)
## Warning in sqrt((b^2) - (4 * a * c)): NaNs produced
## Warning in sqrt((b^2) - (4 * a * c)): NaNs produced
## [1] "x is equal to NaN or NaN"