Error GCD prob

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vikasdev
    New Member
    • Jan 2008
    • 4

    Error GCD prob

    sir ,first of all i want to say that i m a student of b.tech 1st sem.and this question doesn't comprise my projects or assignment.
    i m unable to find out the reason of "garbage value returned by function GCD. .
    if i m using a little different code, its working.the mere difference is that i hav interchanged the conditions and code inside the if-else statement.
    If u trust me then plz help me out.
    else its OK..
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Originally posted by vikasdev
    sir ,first of all i want to say that i m a student of b.tech 1st sem.and this question doesn't comprise my projects or assignment.
    i m unable to find out the reason of "garbage value returned by function GCD. .
    if i m using a little different code, its working.the mere difference is that i hav interchanged the conditions and code inside the if-else statement.
    If u trust me then plz help me out.
    else its OK..

    If the function returns garbage then it means u are using some un-initialized variable.
    or else you are not initializing the return variable properly inside the condition

    Raghuram

    Comment

    • vikasdev
      New Member
      • Jan 2008
      • 4

      #3
      Originally posted by gpraghuram
      If the function returns garbage then it means u are using some un-initialized variable.
      or else you are not initializing the return variable properly inside the condition

      Raghuram
      sir..,
      now i hav changed my code a little bit...previous code was:

      if(r!=0)
      hcf(r,div);
      else

      return(div);

      where r is remainder finally after successive divisions.
      now i hav changed it to:

      sir..,
      now i hav changed my code a little bit...now code is:

      if(r!=0)
      hcf(r,div);
      else{
      if(r==0) //..included afterwards..
      return(div);}
      now its working fine..
      plz tell me why??

      Comment

      Working...