int gcd (int num1, int num2)
{
  int remainder;
  if (num1 > num2)
	remainder = num1 % num2;
  else
	remainder = num2 % num1;
  if(remainder!=0)
  {
	return gcd(remainder, num1);

  }
  return num1;
}
int gcd2 (int num1, int num2)
{
	int remainder;
	return ( remainder = ( num1 > num2 ?  num1 % num2 : num2 % num1)==0 ? num1
			  : gcd2(remainder, num1));
}

its bothering me when passed the same parameters to these two above functions, they give different results.

any idea whats up with them

u need extra parentheses around the = assignment

return ( (remainder = ( num1 > num2 ?  num1 % num2 : num2 % num1) )==0 ? num1
 						  : gcd2(remainder, num1));

You are right. Thank you. program fixed

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.