Mutual recursion: Difference between revisions

Content added Content deleted
(smalltalk)
(awk)
Line 12: Line 12:


<br>(If a language does not allow for a solution using mutually recursive functions then state this rather than give a solution by other means).
<br>(If a language does not allow for a solution using mutually recursive functions then state this rather than give a solution by other means).

=={{header|AWK}}==

In AWK too it is enough both functions are defined before they are really called.

<lang awk>function F(n)
{
if ( n == 0 ) return 1;
return n - M(F(n-1))
}

function M(n)
{
if ( n == 0 ) return 0;
return n - F(M(n-1))
}

BEGIN {
for(i=0; i < 20; i++) {
printf "%3d ", F(i)
}
print ""
for(i=0; i < 20; i++) {
printf "%3d ", M(i)
}
print ""
}</lang>


=={{header|C}}==
=={{header|C}}==