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

Reply

Join Date: May 2004
Posts: 3
Reputation: AmericanD is an unknown quantity at this point 
Solved Threads: 0
AmericanD AmericanD is offline Offline
Newbie Poster

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

 
0
  #1
May 2nd, 2004
  1. int gcd (int num1, int num2)
  2. {
  3. int remainder;
  4. if (num1 > num2)
  5. remainder = num1 % num2;
  6. else
  7. remainder = num2 % num1;
  8. if(remainder!=0)
  9. {
  10. return gcd(remainder, num1);
  11.  
  12. }
  13. return num1;
  14. }
  15. int gcd2 (int num1, int num2)
  16. {
  17. int remainder;
  18. return ( remainder = ( num1 > num2 ? num1 % num2 : num2 % num1)==0 ? num1
  19. : gcd2(remainder, num1));
  20. }

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

any idea whats up with them
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 77
Reputation: infamous is an unknown quantity at this point 
Solved Threads: 2
infamous infamous is offline Offline
Junior Poster in Training

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

 
0
  #2
May 2nd, 2004
u need extra parentheses around the = assignment
  1. return ( (remainder = ( num1 > num2 ? num1 % num2 : num2 % num1) )==0 ? num1
  2. : gcd2(remainder, num1));
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 3
Reputation: AmericanD is an unknown quantity at this point 
Solved Threads: 0
AmericanD AmericanD is offline Offline
Newbie Poster

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

 
0
  #3
May 2nd, 2004
You are right. Thank you. program fixed
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC