Advertisement
a3f

Calculate the natural constant

a3f
Mar 23rd, 2012
1,227
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. REM sum = 1/1! + 2/2! + 3/3! + 4/4! + ... + n/n! : n = 10 ' mathemtically we can reduce it to :
  2. REM sum = 1/0! + 1/1! + 1/2! + 1/3! + ... + 1/(n-1)!          [calculate this]
  3.  ''''''''''''''''''''''''''''''''''''''''''''''''
  4.     let sum = 0
  5.     let factorial = 1
  6. for n = 0 to 100
  7.     if n = 0 then factorial = 1
  8.  
  9.     if n > 0 then factorial = factorial * (n)
  10.  
  11.     sum = sum + 1/factorial
  12.  
  13.  
  14.  
  15.  
  16. next n
  17. ''''''''''''''''''''''''''''''''''''''''
  18.  
  19. print sum
Advertisement
RAW Paste Data Copied
Advertisement