//
// main.cpp
// GCD
//
// Created by Himanshu on 19/09/21.
//
#include <iostream>
using namespace std;
int gcdUsingSubtarction ( int a, int b) {
if ( a == 0 ) {
return b;
}
while ( b ! = 0 ) {
if ( a> b)
a = a - b;
else
b = b - a;
}
return a;
}
int gcdUsingDivision ( int a, int b) {
if ( b == 0 ) {
return a;
} else {
return gcdUsingDivision ( b, a% b) ;
}
}
int main( ) {
int a = 7 , b = 43 ;
printf ( "GCD of %d and %d using subtraction is %d \n " , a, b, gcdUsingSubtarction( a, b) ) ;
printf ( "GCD of %d and %d using division is %d \n " , a, b, gcdUsingDivision( a, b) ) ;
a = 21 ;
b = 343 ;
printf ( "GCD of %d and %d using subtraction is %d \n " , a, b, gcdUsingSubtarction( a, b) ) ;
printf ( "GCD of %d and %d using division is %d \n " , a, b, gcdUsingDivision( a, b) ) ;
return 0 ;
}
Ly8KLy8gIG1haW4uY3BwCi8vICBHQ0QKLy8KLy8gIENyZWF0ZWQgYnkgSGltYW5zaHUgb24gMTkvMDkvMjEuCi8vCgojaW5jbHVkZSA8aW9zdHJlYW0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgZ2NkVXNpbmdTdWJ0YXJjdGlvbiAoaW50IGEsIGludCBiKSB7CiAgICBpZiAoYSA9PSAwKSB7CiAgICAgICAgcmV0dXJuIGI7CiAgICB9CgogICAgd2hpbGUgKGIgIT0gMCkgewogICAgICAgaWYgKGE+YikKICAgICAgICAgIGEgPSBhIC0gYjsKICAgICAgZWxzZQogICAgICAgICBiID0gYiAtIGE7CiAgICAgfQogICAgcmV0dXJuIGE7Cn0KCmludCBnY2RVc2luZ0RpdmlzaW9uIChpbnQgYSwgaW50IGIpIHsKICAgIGlmIChiID09IDApIHsKICAgICAgICByZXR1cm4gYTsKICAgIH0gZWxzZSB7CiAgICAgICAgcmV0dXJuIGdjZFVzaW5nRGl2aXNpb24gKGIsIGElYik7CiAgICB9Cn0KCmludCBtYWluKCkgewogICAgaW50IGEgPSA3LCBiID0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