/* greatest common divisor - Euclidean algorithm
input: x and y.
output: greatest common divisor of x and y,
and the number of iteration.
*/
#include <stdio.h>
int main()
{
int x, y; /* input */
int r;
int noofiteration; /* number of iteration */
printf("type two numbers: ");
scanf("%d%d", &x, &y);
printf("GCD(%d, %d) = ", x, y);
noofiteration = 0;
while (y > 0) {
r = x % y;
x = y;
y = r;
noofiteration = noofiteration + 1; /* count no. of iteration */
}
/* here, x is the GCD */
printf(" %d\n", x);
printf("no. of iteration is %d\n", noofiteration);
return 0;
}