From: mdw Date: Sun, 9 Jul 2000 21:30:49 +0000 (+0000) Subject: Demo program to compute factorials. X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/commitdiff_plain/ff07f5436fde82aa2046965308d3f9d98333bda3 Demo program to compute factorials. --- diff --git a/factorial.c b/factorial.c new file mode 100644 index 0000000..ac2f3fb --- /dev/null +++ b/factorial.c @@ -0,0 +1,72 @@ +/* -*-c-*- + * + * $Id: factorial.c,v 1.1 2000/07/09 21:30:49 mdw Exp $ + * + * Example factorial computation + * + * (c) 2000 Straylight/Edgeware + */ + +/*----- Licensing notice --------------------------------------------------* + * + * This file is part of Catacomb. + * + * Catacomb is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * Catacomb is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with Catacomb; if not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. + */ + +/*----- Revision history --------------------------------------------------* + * + * $Log: factorial.c,v $ + * Revision 1.1 2000/07/09 21:30:49 mdw + * Demo program to compute factorials. + * + */ + +/*----- Header files ------------------------------------------------------*/ + +#include +#include + +#include +#include + +#include "mpmul.h" + +/*----- Main code ---------------------------------------------------------*/ + +int main(int argc, char *argv[]) +{ + unsigned long x; + char *p; + mp *f; + + ego(argv[0]); + + if (argc != 2) { + pquis(stderr, "Usage: $ integer\n"); + exit(EXIT_FAILURE); + } + x = strtoul(argv[1], &p, 0); + if (*p) + die(EXIT_FAILURE, "bad integer `%s'", argv[1]); + f = mp_factorial(x); + mp_writefile(f, stdout, 10); + fputc('\n', stdout); + mp_drop(f); + return (0); +} + +/*----- That's all, folks -------------------------------------------------*/