Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Beginner
Apr 23, 2001

Finding the lcm


The need to find the Icm is pretty common in C++ programming. This is just a basic code for finding the lcm of two integers:
 
int lcm(int large, int small)
{
   int max = large * small; // % until max
   int mult = large; // will address lcm
   int factor = 2; // large * factor until lcm

   while ((mult % small) && (mult <= max))
   {
      mult = large * factor;
      factor++;
   }
   return mult;
}
Sophy Pal
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date