diff options
Diffstat (limited to 'examples/02-prod.c')
| -rw-r--r-- | examples/02-prod.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/examples/02-prod.c b/examples/02-prod.c new file mode 100644 index 0000000..8b7af40 --- /dev/null +++ b/examples/02-prod.c @@ -0,0 +1,36 @@ +/* Calculates the product of $@ */ + +#include <stdio.h> +#include <stdlib.h> + +#include <zahl.h> + +int +main(int argc, char *argv[]) +{ + z_t prod, factor; + jmp_buf env; + char *buf; + int i; + + if (setjmp(env)) + return zperror(argv[0]), 1; + + zsetup(env); + zinit(prod); + zinit(factor); + zsetu(prod, 1); + + for (i = 1; i < argc; i++) { + zsets(factor, argv[i]); + zmul(prod, prod, factor); + } + + printf("%s\n", buf = zstr(prod, NULL, 0)); + free(buf); + + zfree(factor); + zfree(prod); + zunsetup(); + return 0; +} |
