0
help
#include <stdio.h> #include <stdbool.h> int greatestCommonDivisor(int m, int n) //This function implements the Euclidian Algorithm { int r; /* Check For Proper Input */ if ((m == 0) || (n == 0)) return 0; if (m < 0) m = -m; if (n < 0) n = -n; do { r = m % n; if (r == 0) break; m = n; n = r; } while (true); return n; } int main(void) { int num1; int num2; int gcd = greatestCommonDivisor(num1, num2); printf("Please enter two numbers: "); scanf("%d %d", &num1, &num2); printf("The GCD of %d and %d is %d\n", num1, num2, gcd); getchar(); return 0; } how do I find the gcd within the first function of the program? would I put another if statement under the while statement
4 Answers
+ 1
here is your code, i fixed some errors,
it wasn't showing correct ans because your were calculating gcd before initialising num1 and num2.
https://code.sololearn.com/cvV0hjojuoxv/?ref=app
+ 2
you should write
m = -1*m;
n = -1*n;
know it's not mathematics you have to tell the compiler what does -m means
and i don't understand your question clearly,
what do you really want to ask?
here a simple implementation, if wanna go through
https://code.sololearn.com/cM54x9863Iqm/?ref=app
0
When I enter 99 and 66 I should get 33; why am I not getting it; I tested it out on your program; would you like to see the changes I made?
0
Oh okay, now I see; this was very helpful. I seen this exercise on Stackoverflow; but was confused on the comments



