diff --git a/euclid.c b/euclid.c new file mode 100644 index 0000000..352cbb7 --- /dev/null +++ b/euclid.c @@ -0,0 +1,16 @@ +#include +#include + + +int euclid(int m, int n) +{ + int remainder; + + remainder = m % n; + while(remainder != 0) { + m = n; + n = remainder; + remainder = m % n; + } + return(n); +} diff --git a/main.c b/main.c new file mode 100644 index 0000000..62a8bec --- /dev/null +++ b/main.c @@ -0,0 +1,19 @@ +#include +#include + +void main() +{ + char str[100]; + int m; + int n; + int answer; + + printf("Enter an integer:"); + fgets(str, 100, stdin); + m = atoi(str); + printf("Enter another integer:"); + fgets(str, 100, stdin); + n = atoi(str); + answer = euclid(m, n); + printf("The greatest common divisor between these two integers is %d\n", answer); +}