Sum of a series: Difference between revisions

no edit summary
(Logo)
No edit summary
Line 1:
{{task}}Display the sum of a finite series for a given range.
 
For this task, use S(x) = 1/x^2, from 1 to 1000. (This approximates the Riemann zeta function. The Basel problem solved this: zeta(2) = πp<sup>2</sup>/6.)
 
=={{header|Ada}}==
Line 32:
int main()
{
unsigned int start = 1;
unsigned int end = 1000;
double sum = 0;
double sum = 0;
for( unsigned int x = start;
x <= end;
++x )
++x )
{
{
sum += f(x);
}
}
}
std::cout << "Sum of f(x) from " << start << " to " << end << " is " << sum << std::endl;
return 0;
}
 
Line 50:
double f(double x)
{
return ( 1 / ( x * x ) );
}
</pre>
Line 163:
map { $sum += 1 / ( $_ * $_ ) } (1..1000);
print "$sum\n";
</pre>
 
=={{header|Pop11}}==
 
<pre>
lvars s = 0, j;
for j from 1 to 1000 do
s + 1.0/(j*j) -> s;
endfor;
 
s =>
</pre>
 
Anonymous user