Sum of a series: Difference between revisions

Content added Content deleted
(Sum of a series en Yabasic)
(→‎{{header|ALGOL 68}}: Corrected the range of the summation and formatted the output.)
Line 125: Line 125:


=={{header|ALGOL 68}}==
=={{header|ALGOL 68}}==
{{works with|ALGOL 68|Revision 1 - no extensions to language used}}

{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny]}}

{{works with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d]}}
<lang algol68>MODE RANGE = STRUCT(INT lwb, upb);
<lang algol68>MODE RANGE = STRUCT(INT lwb, upb);


Line 141: Line 136:


test:(
test:(
RANGE range = (1,100);
RANGE range = (1,1000);
PROC f = (INT x)LONG REAL: LENG REAL(1) / LENG REAL(x)**2;
PROC f = (INT x)LONG REAL: LENG REAL(1) / LENG REAL(x)**2;
print(("Sum of f(x) from", lwb OF range, " to ",upb OF range," is ", SHORTEN sum(f,range),".", new line))
print(("Sum of f(x) from ", whole(lwb OF range, 0), " to ",whole(upb OF range, 0)," is ", fixed(SHORTEN sum(f,range),-8,5),".", new line))
)</lang>
)</lang>
Output:
Output:
<pre>
<pre>
Sum of f(x) from +1 to +100 is +1.63498390018489e +0.
Sum of f(x) from 1 to 1000 is 1.64393.
</pre>
</pre>