0
Q: 4 (b)     Write an application that estimates the value of the mathematical constant e by using the formula
                  e = 1+ (1/1!) + (1/2!) + (1/3!) . . .

//////////////////////////////////////////////////////////////////////////////////////////////
 
public class euler {
    public static void main(String args[])
    {
        double e = 1;
       
        for(int x = 1; x < 18; x++)
            e = e + 1/(double)fictorial(x);
        System.out.println("e: "+ e);
       
    }


   
    public static double fictorial(int n)
    {
        int x;
    if(n < 1)
    {
        return 0;
    }
    else
    {
        if(n == 1)
        {
            return 1;
        }
        else if(n > 1)
        {
            return n*fictorial(n-1);
        }
    }
        return 0;
    }
}

Post a Comment

Emoticon
:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.

 
Top