Mutual recursion: Difference between revisions
Content deleted Content added
Added FreeBASIC |
|||
Line 236:
In AWK it is enough that both functions are defined somewhere. It matters not whether the BEGIN block is before or after the function definitions.
<lang awk>
#!/usr/local/bin/gawk -f
# User defined functions
return n - M(F(n-1))▼
function F(n)
function M(n)
▲ 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>
{{out}}
<pre>
$ awk -f mutual_recursion.awk
1 1 2 2 3 3 4 5 5 6 6 7 8 8 9 9 10 11 11 12 13
0 0 1 2 2 3 4 4 5 6 6 7 7 8 9 9 10 11 11 12 12
</pre>
=={{header|BASIC}}==
|