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=1Second approximation is pi/4=1-1/3Required outputs: approximation 1= 1.0third: pi/4=1-1/3+1/5
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