954,123 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

I dont see any difference between these 2 functions, DO YOU?

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

AmericanD
Newbie Poster
3 posts since May 2004
Reputation Points: 10
Solved Threads: 0
 

u need extra parentheses around the = assignment

return ( (remainder = ( num1 > num2 ?  num1 % num2 : num2 % num1) )==0 ? num1
 						  : gcd2(remainder, num1));
infamous
Junior Poster in Training
77 posts since Mar 2004
Reputation Points: 47
Solved Threads: 2
 

You are right. Thank you. program fixed

AmericanD
Newbie Poster
3 posts since May 2004
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You