- Joined
- Feb 17, 2007
OK, so calculating the result in Excel, we get 0.239560747 . This is as many decimal places as Excel can do.
Now, let's write a computer program in the Pascal programming language.
program foxtrot;
var k, goal : longint;
one, factor, sum, previous : real;
begin
write(' How many iterations? ');
readln( goal );
writeln;
sum := 0.0;
one := -1.0;
factor := 0.0;
k := 0;
repeat
previous := factor;
k := k + 1;
one := -1.0 * one;
factor := ( one * k * k ) / ( 1.0 * k * k * k + 1.0 );
sum := factor + sum
until k = goal;
writeln;
writeln(' The sum = ', sum, ' after ', k, ' iterations. ');
writeln
end.
Let's compare the answer with the number of iterations.
iterations ....................... result
1,000 ....................... 0.23906099734
10,000 ..................... 0.23951074984
100,000 .................... 0.23955574735
1,000,000 ................. 0.23956024728
10,000,000 ............... 0.23956069736
100,000,000 ............. 0.23956074230
200,000,000 ............. 0.23956074479
300,000,000 ............. 0.23956074562
400,000,000 ............. 0.23956074603
500,000,000 ............. 0.23956074628
1,000,000,000 ........... 0.23956074677
So as we can see, it took a billion iterations to achieve the Excel result to 9 decimal places.
Now, let's write a computer program in the Pascal programming language.
program foxtrot;
var k, goal : longint;
one, factor, sum, previous : real;
begin
write(' How many iterations? ');
readln( goal );
writeln;
sum := 0.0;
one := -1.0;
factor := 0.0;
k := 0;
repeat
previous := factor;
k := k + 1;
one := -1.0 * one;
factor := ( one * k * k ) / ( 1.0 * k * k * k + 1.0 );
sum := factor + sum
until k = goal;
writeln;
writeln(' The sum = ', sum, ' after ', k, ' iterations. ');
writeln
end.
Let's compare the answer with the number of iterations.
iterations ....................... result
1,000 ....................... 0.23906099734
10,000 ..................... 0.23951074984
100,000 .................... 0.23955574735
1,000,000 ................. 0.23956024728
10,000,000 ............... 0.23956069736
100,000,000 ............. 0.23956074230
200,000,000 ............. 0.23956074479
300,000,000 ............. 0.23956074562
400,000,000 ............. 0.23956074603
500,000,000 ............. 0.23956074628
1,000,000,000 ........... 0.23956074677
So as we can see, it took a billion iterations to achieve the Excel result to 9 decimal places.
Last edited:

