| control/gcd-prog-3a-print.c - En mere basal udgave af Euclids algoritme - som printer rækken af tal. | Lektion 4 - slide 3 : 14 Program 6 |
#include <stdio.h>
int main(void) {
int i, j, a, b;
printf("Enter two positive integers: ");
scanf("%d %d", &i, &j);
a = i; b = j;
while (a != b)
if (a > b){
a = a - b;
printf("%d ", a);
}
else{
b = b - a;
printf("%d ", b);
}
printf("\nGCD of %d and %d is %d\n\n", i, j, a);
return 0;
}