diff options
Diffstat (limited to 'docs/history/15-o3/code/examples/fact.zc')
| -rw-r--r-- | docs/history/15-o3/code/examples/fact.zc | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/docs/history/15-o3/code/examples/fact.zc b/docs/history/15-o3/code/examples/fact.zc new file mode 100644 index 0000000..2a218b2 --- /dev/null +++ b/docs/history/15-o3/code/examples/fact.zc @@ -0,0 +1,4 @@ +fn fact(n) { if (n < 2) return 1; return n * fact(n - 1); } +// prints in binary, like the old asm example +fn bin(n) { if (n > 1) bin(n >> 1); putc('0' + (n & 1)); return 0; } +fn main() { bin(fact(10)); putc(10); putn(fact(10)); putc(10); return 0; } |
