Last active
February 3, 2021 05:48
-
-
Save vmxdev/d89f7420bc04c0c904fd747b097335d5 to your computer and use it in GitHub Desktop.
Calculate factorials using gmp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* $ cc -O3 -Wall -pedantic -Wextra fact.c -lgmp | |
*/ | |
#include <stdio.h> | |
#include <gmp.h> | |
static void | |
factorial(long n, mpz_t r) | |
{ | |
mpz_init_set_si(r, 1); | |
for (; n > 1; n--) { | |
mpz_mul_si(r, r, n); | |
} | |
} | |
int | |
main (void) | |
{ | |
int i; | |
mpz_t r; | |
for (i=0; i<14888; i++) { | |
factorial(i, r); | |
gmp_printf ("%Zd\n", r); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment