mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Factorial macro example.
This commit is contained in:
16
resources/examples/factorial_macro.c3
Normal file
16
resources/examples/factorial_macro.c3
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
macro int factorial($n)
|
||||||
|
{
|
||||||
|
$if ($n == 0):
|
||||||
|
return 1;
|
||||||
|
$else:
|
||||||
|
return $n * @factorial($n - 1);
|
||||||
|
$endif;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern func void printf(char *fmt, ...);
|
||||||
|
|
||||||
|
func void main()
|
||||||
|
{
|
||||||
|
int x = @factorial(12);
|
||||||
|
printf("12! = %d\n", x);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user