home work help =)

This is a discussion on home work help =) within the C Programming forums, part of the General Programming Boards category; this program calculates the approximate value of e to the x(e^x) and subtracts that value from the exact value. im ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    1

    Arrow home work help =)

    this program calculates the approximate value of e to the x(e^x)
    and subtracts that value from the exact value. im not soo sure if its working correctly, well it runs but im not sure im getting the correct out put, its for a school hw assignment. also what is the place holder symbol for double, i have to do this program for double and for float.


    #include <stdio.h>
    #include <math.h>

    float factorial(float);//factorial function header
    float myE(float,float);

    main()
    {
    float exponent_e,non_pierc,error_amt;
    float x=2.0;
    float n = 0;


    non_pierc=0.0;
    exponent_e=exp(x);

    //printf("X= %f\n",x);

    for(n=10;n<=35;n++)
    {

    non_pierc=myE(x,n);

    error_amt=(exponent_e-non_pierc);
    printf("%.0f | %.12f \n",n,error_amt);

    }

    return 0;
    }
    /////////////////////////////
    float myE (float x, float n)
    {
    if (n<1.0) return 1.0;
    else
    return ((pow(x,n)/factorial(n)) + myE(x,n - 1.0));
    }

    float factorial(float a)
    {
    if(a <=1)
    return 1;
    else
    return a * factorial(a -1);
    }

  2. #2
    Unregistered
    Guest
    I think the placeholder for double is %lf, which stands for long float.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem in accessing root home folder....
    By Bargi in forum Linux Programming
    Replies: 1
    Last Post: 02-13-2008, 05:50 AM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 11:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 11:39 PM
  4. C++ software for home work
    By rgk44 in forum C++ Programming
    Replies: 12
    Last Post: 02-15-2006, 04:00 AM
  5. Problems in getting OpenGL to work
    By zonf in forum C Programming
    Replies: 5
    Last Post: 02-13-2006, 04:48 AM

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