the code:
/* find the greatest common divisor of two integers */
#include <stdio.h>
int gcd(int p, int q);
void main()
{
int u,v,g;
printf("Enter two numbers: ");
scanf("%d %d",&u,&v);
g=gcd(u,v);
printf("Greatest Common Divisor of %d and %d is %d",u,v,g);
}
int gcd(int a, int b)
{
int m;
m=a%b;
if(m==0)
return(b);
else
gcd(b,m);
}
is working properly on https://www.onlinegdb.com/online_c++_compiler
the code is NOT working on macosx/ sierra with Apple LLVM version 10.0.0 (clang-1000.10.44.4) since the value of the returned variable 'b' does not get assigned to the variable 'g' in line 'g=gcd(u,v);'
'g' always gets the value of 0.
how could this issue be fixed on the mac?
could not find a workaround on stackoverflow.