TPK algorithm: Difference between revisions

Content deleted Content added
C implementation: format code
Ricvelozo (talk | contribs)
No edit summary
Line 19:
 
==[[ALGOL 60]] implementation==
<syntaxhighlight lang="Pascal" line>
begin integer i; real y; real array a[0:10];
real procedure f(t); real t; value t;
Line 37:
This shows a C implementation equivalent to the above ALGOL 60.
 
<syntaxhighlight lang="C" line>
#include <math.h>
#include <stdio.h>
 
double f (double t)
{
return sqrt(fabs (t)) + 5 * pow (t, 3);
}
 
int main (void)
{
double a[11], y;
Line 53:
 
for (int i = 10; i >= 0; i--) {
y = f (a[i]);
if (y > 400)
printf("%d TOO LARGE\n", i);
else
printf("%d %f.16g\n", i, y);
}
}
Line 65:
This shows a Python implementation.
 
<syntaxhighlight lang="pythonPython" line>
importfrom math import sqrt
 
def f(t) -> float:
return math.sqrt(abs(t)) + 5 * t ** 3
 
a = [float(input()) for _ in range(11)]