diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2022-11-07 14:28:54 +0200 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2022-11-07 16:48:01 +0200 |
commit | 51e22a9a559a9961f43875c68f099540ffae0c6d (patch) | |
tree | fee16829f1cc48c54fd82d94ec5293a0ecd83cfb | |
parent | c49bf6ce1b8923b0ccce0cb653489759feb79f42 (diff) | |
download | gcd-51e22a9a559a9961f43875c68f099540ffae0c6d.tar.gz |
Update gcd-gmp.c
-rw-r--r-- | gcd-gmp.c | 31 |
1 files changed, 14 insertions, 17 deletions
@@ -45,25 +45,22 @@ main (int argc, char *argv[]) if (argc > 1) { n = argc - 1; - a = malloc (sizeof (mpz_t) * n); - if (NULL != a) - { - for (i = 1; i <= n; i++) - mpz_init_set_str (a[i - 1], argv[i], 10); + a = (mpz_t *) malloc (n * sizeof (mpz_t)); + if (!a) + return EXIT_FAILURE; - mpz_init (g); - gcdn (g, a, n); - mpz_out_str (NULL, 10, g); - printf ("\n"); + for (i = 1; i <= n; i++) + mpz_init_set_str (a[i - 1], argv[i], 10); - /* No need actually before exit */ - mpz_clear (g); - for (i = 1; i <= n; i++) - mpz_clear (a[i - 1]); - free (a); - return EXIT_SUCCESS; - } - return EXIT_FAILURE; + mpz_init (g); + gcdn (g, a, n); + mpz_out_str (NULL, 10, g); + printf ("\n"); + + mpz_clear (g); + for (i = 1; i <= n; i++) + mpz_clear (a[i - 1]); + free (a); } return EXIT_SUCCESS; } |