C++ programming I need help creating a formula for the Euclidean algorithm,which
ID: 3609699 • Letter: C
Question
C++ programming I need help creating a formula for the Euclidean algorithm,which will find the greatest common divisor for a fractiona/b. Given two natural numbers, a and b,- check if b is zero; if yes, a is the gcd
- if not, let r = a modulus b,
- a = b, b = r
- repeat steps 2 and 3 until r is 0
- when r is 0, b will be the GCD
let a = 42 and b = 72
r = 42 modulus 72 = 42
r = 72 modulus 42 = 30
r = 42 modulus 30 = 12
r = 30 modulus 12 = 6
r = 12 modulus 6 = 0
since the r is 0, 6 is the GCD I am extremely confused on how to to this C++ programming I need help creating a formula for the Euclidean algorithm,which will find the greatest common divisor for a fractiona/b. Given two natural numbers, a and b,
- check if b is zero; if yes, a is the gcd
- if not, let r = a modulus b,
- a = b, b = r
- repeat steps 2 and 3 until r is 0
- when r is 0, b will be the GCD
let a = 42 and b = 72
r = 42 modulus 72 = 42
r = 72 modulus 42 = 30
r = 42 modulus 30 = 12
r = 30 modulus 12 = 6
r = 12 modulus 6 = 0
since the r is 0, 6 is the GCD I am extremely confused on how to to this
Explanation / Answer
please rate - thanks # include int main() { int a,b,r; couta; coutb; if(b==0) r=a; else {r=a%b; while(r!=0) {a=b; b=r; r=a%b; } } coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.