Her er en naiv løsning på GCD problemet:#include <stdio.h>
#include <stdlib.h>
int main(void) {
int i, j, small, large, n;
do {
printf("Enter two non-negative integers: ");
scanf("%d %d", &i, &j);
small = i <= j ? i : j;
large = i <= j ? j : i;
if (small < 0 || large < 0)
printf("Bye");
else if (small == 0 && large == 0)
printf("We cannot find gcd in case both inputs are zero\n");
else if (small == 0)
printf("GCD of 0 and %d is %d\n", large, large);
else {
/* small > 0 && large > 0 */
n = small;
while((small % n != 0 || large % n != 0) && (n >= 2)){
--n;
}
/* (small % n == 0 && large % n == 0) || (n == 1) */
printf("GCD of %d and %d is %d\n", large, small, n);
}
} while (i >= 0 && j >= 0);
return EXIT_SUCCESS;
}