Sat, 30th Aug 2008 09:10:57
Never fear, this site is here

#Who loves e?

Language: C++
Written by nemmy on 2007-12-11 21:37:00

#include <iostream>

// stems from the fact that e = 1/1! + 1/2! + 1/3! +... etc

long factorial(long number){
    long answer = 1;
    for(int i = 1; i <= number; i++){
        answer *= i;
   }
   return answer;
}
       
int main(int argc, char *argv[]){
    double e = 0.0;
    for(int iterations = 0; iterations < 20; iterations++){
        e = e + (1.0/(float)factorial(iterations));
    }
    printf("%.10f\n", e);
    return 0;
}
Powered by Debian, Jack Daniels, Guinness, and excessive quantities of caffeine and sugar.