More content will be added soon , if you have any different or better solution then please post in the comment section of the respective question.
// Iterative algorithmint gcd(int a, int b){int temp;while(b){temp = a % b;a = b;b = temp;}return(a);}// Recursive algorithmint gcd_recurse(int a, int b){int temp;temp = a % b;if (temp == 0){return(b);}else{return(gcd_recurse(b, temp));}}
Post a Comment
1 comments:
// Iterative algorithm
int gcd(int a, int b)
{
int temp;
while(b)
{
temp = a % b;
a = b;
b = temp;
}
return(a);
}
// Recursive algorithm
int gcd_recurse(int a, int b)
{
int temp;
temp = a % b;
if (temp == 0)
{
return(b);
}
else
{
return(gcd_recurse(b, temp));
}
}
Post a Comment