RSS Forums RSS
Please support our C++ advertiser: Programming Forums

help with Greatest common divisor

Join Date: Jun 2005
Posts: 33
Reputation: shre86 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
shre86 shre86 is offline Offline
Light Poster

Re: help with Greatest common divisor

  #2  
Jul 1st, 2005
i ll give u a fn or the gcd of 2 nos..

int gcd(int x,int y)
{
   if ( y>x )
      swap(x,y);
   while ( y!=0 )
   {
      temp=y;
      y=x-y;
      x=temp;
      if ( y>x )
         swap(x,y);
   }
   return x;
}
<< moderator edit: added [code][/code] tags and formatting; added missing semicolon >>

just call this fn for the first 2 nos.. then the gcd and the 3rd no. and then there gcd and the 4th no. and so on..
till all the nos are over.. u ll get ur final answer...
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:53 am.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC