Help please

This is a discussion on Help please within the C++ Programming forums, part of the General Programming Boards category; I am a beginner to programming. I need help please. I am supposed to write my own function named myExp ...

  1. #1
    Unregistered
    Guest

    Help please

    I am a beginner to programming. I need help please. I am supposed to write my own function named myExp to compute exponential functions without using the library function Exp. The prototype should be
    double myExp(double);
    I am not supposed to use the pow function either. Instead I am supposed to use the series expansion:
    e^x = 1 + x/1! + x^2/2! + x^3/3! + x^n/n!
    From this I am supposed to notice that the nth term in the series may be obtained from the (n-1)th term by multiplying by x/n. Also, I have to write a loop that generates one term on each pass and adds it to the sum of all previous terms, and exit the loop when the term is less than 0.0000001. In addition to myExp funtion, the program should contain a main function to prompt the user enter real number x and then compares the value that the function call myExp(x) returns with the value returned by the library function call exp(x).
    Your help is appreciated, thank you so much.

  2. #2
    Unregistered
    Guest

    wow wow..

    ok send your script so far.. or simplify your question, you dont need to send all the details yet.. what exactly do you want this function to do? (simplified, i dont want to have to think that much)

  3. #3
    Registered User JasonLikesJava's Avatar
    Join Date
    Mar 2002
    Posts
    175
    Maybe something like this would work for starters:

    int total=1;
    int term;
    int i=1;
    while (term>0.0000001)
    {
    term=input^i/factoral(i);
    total+=
    {

    int factoral(int x)
    {
    int total=x;
    for (int i=x;i>0;i++)
    {
    total*=(x-1);
    }
    return total;
    }

  4. #4
    Registered User JasonLikesJava's Avatar
    Join Date
    Mar 2002
    Posts
    175
    and of course you'll have to worry about the input^i part

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21