#!/usr/bin/perl ########################################################################### # # partialsums.pl # # Write a program in the language of your choice to compute and display the first 800,000 partial sums for the infinite series # # 1/1^2 + 1/2^2 + 1/3^2 + 1/4^2 + 1/5^2 + 1/6^2 + 1/7^2 + 1/8^2 + 1/9^2 + ... # # (c)Ken Owen 2011 # ########################################################################### use constant PI => 4 * atan2(1, 1); my $loops=800000; my $answer=0; my $match=PI**(2)/6; for($i=1; $i<$loops; $i++){ $answer+=1/$i**2; #uncomment the next line to see the progression #print "i=" . $i . " answer=" . $answer . "\n"; } print "After " . $loops . " loops, the answer is " . $answer . "\n"; print "PI=" . PI . "\n"; print "pi^2/6=" . $match . "\n";