summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2022-11-07 14:28:54 +0200
committerIgor Pashev <pashev.igor@gmail.com>2022-11-07 16:48:01 +0200
commit51e22a9a559a9961f43875c68f099540ffae0c6d (patch)
treefee16829f1cc48c54fd82d94ec5293a0ecd83cfb
parentc49bf6ce1b8923b0ccce0cb653489759feb79f42 (diff)
downloadgcd-51e22a9a559a9961f43875c68f099540ffae0c6d.tar.gz
Update gcd-gmp.c
-rw-r--r--gcd-gmp.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/gcd-gmp.c b/gcd-gmp.c
index 41213cc..5bedcd2 100644
--- a/gcd-gmp.c
+++ b/gcd-gmp.c
@@ -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;
}