#includeusing namespace std; int functionGCD(int, int); int main() { int a; int
ID: 3655451 • Letter: #
Question
#includeusing namespace std; int functionGCD(int, int); int main() { int a; int b; printf("Enter two numbers : "); scanf("%d %d", &a,&b); functionGCD(a,b); system("pause"); } int functionGCD(int a, int b) { PLease some one can do this more readable! int gcd; if (a > b) { int temp = a; a = b; b = temp; } while(true) { int reminder = b % a; if (reminder == 0) { gcd = a; break; } else { b = a; a = reminder; } } printf("GCD = %d " , a ,b); cin.get();cin.get(); return 0; }Explanation / Answer
//fixed for readability, but your GCD is not the greatest common denominator... #include #include using namespace std; int functionGCD(int, int); int main() { int a; int b; printf("Enter two numbers : "); scanf("%d",&a); scanf("%d",&b); functionGCD(a,b); system("pause"); return 0; } int functionGCD(int a, int b) { int temp; int reminder; int gcd; if (a > b) { temp = a; a = b; b = temp; } while(true) { reminder = b % a; if (reminder == 0) { gcd = a; break; } else { b = a; a = reminder; } } printf("GCD = %d", a); system("pause"); return 0; }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.