Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
#include <stdlib.h>
static int
gcd (int a, int b)
{
static int pass = 0;
++pass;
printf ("\n---Pass #%d---\n", pass);
printf ("a = %d, b = %d\n", a, b);
if (b == 0)
return a;
else
return gcd (b, a % b);
}
int
main (int argc, char **argv)
{
int a, b, solution;
if (argc != 3)
{
printf ("Input the first number ");
scanf ("%d", &a);
printf ("Input the second number ");
scanf ("%d", &b);
}
else
{
a = strtol (argv[1], NULL, 0);
b = strtol (argv[2], NULL, 0);
}
solution = gcd (a, b);
printf ("The GCD of (%d, %d) is %d\n", a, b, solution);
printf ("For example, it could be (%d, %d)\n", a / solution, b / solution);
return 0;
}