Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating help

Status
Not open for further replies.

ogito

Programmer
Nov 14, 2003
4
US
How would I calculate an infinite series like this in a loop. 4 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11 + etc. The user inputs how far to go like, 1 would be 4, 2 would be 2.667. 3 would be 3.467. How would I account for the fact that there is a + and - that switches?
 
The i'th term, if the first term is the 0'th, is (-1^i)*(4/(2*i+1)).

So the user puts in, say, N.
The sum is, say, Sum=0;
The loop is (i=0;i<N;i++) {Sum=Sum+(as above)}

Bob Rashkin
rrashkin@csc.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top