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:

Quote:

Number one: code and execute a program that will approximiate the value of (pi)/4 using this formula:

Quote:

pi/4=1-1/3+1/5-1/7+1/9 . . . .

Quote:

First approximation is pi/4=1

Quote:

Second approximation is pi/4=1-1/3

Quote:

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

Re: Hi, could somebody assist me please?

Quote:

*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