- #1
KevinMulito
- 1
- 0
I am currently working on computer program that has to find the sum of during looping:
1 + 1/2 + 1/3 + 1/4 + etc.
So the loop looks something like this:
sum = 1;
counter = 2;
while(...){
sum = sum + (1/counter);
counter = counter +1;
}
My general question however is purely mathematical.
I am currently using a basic counter variable to keep track of what the next denominator value will be, but I was hoping there was some formula I could be used to go from: 1/2 to 1/3, then 1/3 to 1/4. I am unable to find a consistent relationship between each value and the next in order to simplify my code. Any suggestions would be greatly appreciated.
1 + 1/2 + 1/3 + 1/4 + etc.
So the loop looks something like this:
sum = 1;
counter = 2;
while(...){
sum = sum + (1/counter);
counter = counter +1;
}
My general question however is purely mathematical.
I am currently using a basic counter variable to keep track of what the next denominator value will be, but I was hoping there was some formula I could be used to go from: 1/2 to 1/3, then 1/3 to 1/4. I am unable to find a consistent relationship between each value and the next in order to simplify my code. Any suggestions would be greatly appreciated.