GCD of two numbers

can someone here help me with the GCD code …i got to know the concept but i am not able to convert it into code…please help me out here as it is also asking to write a function and i haven’t studied function yet

@akshat42bajpai the first approach is
int gcd( int a, int b)

{

// Everything divides 0

if (a == 0)

return b;

if (b == 0)

return a;

// base case

if (a == b)

return a;

// a is greater

if (a > b)

return gcd(a-b, b);

return gcd(a, b-a);

}
while the optimise one is this
int gcd( int a, int b)

{

if (b == 0)

return a;

return gcd(b, a % b);

`}
if you have a dout feel free to ask and if clear mark it as resolved

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

how this programm is giving GCD…i even dry run it but i am not able to find GCD…i took two numbers 98 and 56…so last if condition will get true… anb both the return will be executed and 56-98 would be -42 than how this is giving the GCD