summaryrefslogtreecommitdiff
path: root/gcd.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcd.c')
-rw-r--r--gcd.c64
1 files changed, 35 insertions, 29 deletions
diff --git a/gcd.c b/gcd.c
index ea99592..227be89 100644
--- a/gcd.c
+++ b/gcd.c
@@ -1,46 +1,52 @@
#include <stdlib.h>
#include <stdio.h>
-static unsigned long int gcd2(unsigned long int a, unsigned long int b)
+static unsigned long int
+gcd2 (unsigned long int a, unsigned long int b)
{
- unsigned long int c;
- while (b != 0) {
- c = b;
- b = a % b;
- a = c;
+ unsigned long int c;
+ while (b != 0)
+ {
+ c = b;
+ b = a % b;
+ a = c;
}
- return a;
+ return a;
}
-static unsigned long int gcdn(unsigned long int *a, size_t n)
+static unsigned long int
+gcdn (unsigned long int *a, size_t n)
{
- unsigned long int r;
- size_t i;
- r = a[0];
- for(i = 1; i < n; i++) {
- r = gcd2(r, a[i]);
+ unsigned long int r;
+ size_t i;
+ r = a[0];
+ for (i = 1; i < n; i++)
+ {
+ r = gcd2 (r, a[i]);
}
- return r;
+ return r;
}
-int main (int argc, char *argv[])
+int
+main (int argc, char *argv[])
{
- unsigned long int *a;
- size_t i, n;
+ unsigned long int *a;
+ size_t i, n;
- if (argc > 1) {
- n = (size_t)(argc - 1);
- a = (unsigned long int*) malloc(sizeof(unsigned long int) * n);
- if (NULL != a) {
- for (i = 1; i <= n; i++)
- a[i-1] = strtoul(argv[i], NULL, 10);
- printf("%lu\n", gcdn(a, n));
- free(a);
- return EXIT_SUCCESS;
+ if (argc > 1)
+ {
+ n = (size_t) (argc - 1);
+ a = (unsigned long int *) malloc (sizeof (unsigned long int) * n);
+ if (NULL != a)
+ {
+ for (i = 1; i <= n; i++)
+ a[i - 1] = strtoul (argv[i], NULL, 10);
+ printf ("%lu\n", gcdn (a, n));
+ free (a);
+ return EXIT_SUCCESS;
}
- return EXIT_FAILURE;
+ return EXIT_FAILURE;
}
- return EXIT_SUCCESS;
+ return EXIT_SUCCESS;
}
-