0

I'm trying to create and use a function that calculates the factorial of a given number and use this in an another function that calculates the Euler's Number. However i don't understand why the code is giving the + signs on the output. End project needs to be without the + signs.

I know that i could simply use factorial() and exp() but i need to calculate them this way for a project.

calc_fact <- function(m){
 factorial = 1

  if(m>0){
    for(i in 1:m) {
      factorial = factorial * i
    }
  }
  return(factorial)
  
}

emake <- function(n){
  e <- 0
  for (i in 0:n){
    e <- e+ 1/(calc_fact(i))
  }
  return(e)
}

emake(10)

Maxis
  • 1
  • 2
    What do you mean by + signs? What is the result of `enake(10)`? – Onyambu Oct 21 '22 at 13:23
  • Your code is seemingly working fine on my end. – jpsmith Oct 21 '22 at 14:07
  • If you're displaying a "+" symbol that you don't want, then you need to learn the difference between a string containing numerals and a number -- as well as how to specify the **format** of a numerical value when displayed or printed. – Carl Witthoft Oct 21 '22 at 16:55

0 Answers0