Thread: Hi, could somebody assist me please?

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    3

    Question Hi, could somebody assist me please?

    Hey there, I am a high school student in a C++ 2 programming class. Next week we have our final exam, but yesterday our teacher gave us the 6 programs that we mite have to do.

    The longest program is probably 30 lines, and just consists of many for/do while loops.

    I have completed three of them, but the other 3 I do not really understand.

    If someone could just give me some tips or explain them to me, I would be very appreciative.

    Here they are:

    Number one: code and execute a program that will approximiate the value of (pi)/4 using this formula:
    pi/4=1-1/3+1/5-1/7+1/9 . . . .
    First approximation is pi/4=1
    Second approximation is pi/4=1-1/3
    third: pi/4=1-1/3+1/5
    Required outputs: approximation 1= 1.0
    aprox 2: =.0667
    3:= .867

    Please stop when the absolute difference is between two succesive approximations are less than .01.


    //I think that for this one I nest for-loops, but I am not clear on the forumla.

    Question 2:
    The number e can be approximated by the forumla:
    e1= 1+1/1
    e2= 1+1/1*(1+1/2)
    e3= 1+1/1*(1+1/2*(1+1/3*(1+1/4)))

    However, a better approximation would be:
    e100= 1+1/1*(1+1/2*(1+1/3*(1+1/4*(1+1/5*(1+1/6( . . .1/99*(...1+1/100))))).

    The teacher asks to code and execute the program which will calculate and print out e1, e2, through e10 and also e100.

    Outputs:
    approximation 1 of e is 2.0
    aprox 2 of e is 2.5
    aprox of 3 of e is 2.66666675

    This one confuses me. It seems like I will be nesting loops, but I am most confused about this program.

    Question 3:
    It can be shown that the irration number e= 2.71828. . . can be approximatd by taking as many terms as desired in the relation

    e=1+1/1!+1/2!+1/3!+1/4!. . . .

    1st approximation ois 1
    2nd is 1+1/1!=2.
    3rd is 1+1/1!+1/2!=2.5
    4th is 1+1/1!+1/2!+1/3!=2.666

    Please print out the approximation, stop when the absolute difference in 2 successive approximations is less than .001.

    output:
    approx 1 of e is 1.
    aprrox od 2 of e 2.0.
    approx of 3 of e is 2.5
    the x approximtion of e is x.xxxxxxxxxx

    //Do while and while loops? Could someone assist me with the formulas.

    -----------
    I am not asking anyone here to do it for me, I am just looking for help. If you can, please pm or email me, reply to this, or im me at Worthlessgaming on AIM or Drworthless on AIM.

    Thanks in advance,
    Drworthless
    Last edited by Drworthless; 06-12-2002 at 07:01 PM.

  2. #2
    Registered User Mario's Avatar
    Join Date
    May 2002
    Posts
    317

    Re: Hi, could somebody assist me please?

    Originally posted by Drworthless
    //I think that for this one I nest for-loops, but I am not clear on the forumla.
    Not really. I may have missed something but to me a While loop will do the trick. You just need to manage a few counters in order to do the calculation...

    Notice the patern in pi/4=1-1/3+1/5-1/7+1/9... that's 1/1 followed by 1/3, followed by 1/5... so you have to manage a counter that increments 2 each iteration... also, it's - then +, then -, then plus... so a boolean that switches values each iteration will be all you need to check on which operator to use...

    You will finally have to check on each iteration if the previous 1/x-2 minus the current 1/x is equal or less to .01. If so, exit the loop.

    So basically one single loop will do it.

    I can get back to you later to check on the other questions
    Regards,
    Mario Figueiredo
    Using Borland C++ Builder 5

    Read the Tao of Programming
    This advise was brought to you by the Comitee for a Service Packless World

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    3
    mind if i instant message you?

  4. #4
    Registered User Mario's Avatar
    Join Date
    May 2002
    Posts
    317
    err... nope. That's what that thing is there for.

    Anyways, It's a 1:45am here. I'm just a few keystrokes from going to bed
    Regards,
    Mario Figueiredo
    Using Borland C++ Builder 5

    Read the Tao of Programming
    This advise was brought to you by the Comitee for a Service Packless World

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please could someone assist me with double digits
    By ben2000 in forum C Programming
    Replies: 41
    Last Post: 07-31-2007, 05:54 PM
  2. Replies: 4
    Last Post: 06-12-2005, 02:57 PM
  3. ifstream question, please assist!
    By ss3x in forum C++ Programming
    Replies: 6
    Last Post: 04-21-2002, 10:24 AM