Code Snippets

  

C# Source Code


Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 99,792 C# Programmers for FREE! Ask your question and get quick answers from experts. There are 1,620 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!




Get the LCM divisible by a range of numbers

A brute-force method of getting the least common multiple in a range of numbers.

Submitted By: RodgerB
Actions:
Rating:
Views: 229

Language: C#

Last Modified: May 11, 2008
Instructions:
1) Copy and paste the function into a class.
2) Read how to call the function.

Snippet


  1. static uint LCM(int min, int max)
  2. {
  3.     uint numOk = 1;
  4.     bool running = true;
  5.  
  6.     while (running)
  7.     {
  8.         for (int i = max; i >= min; i--)
  9.         {
  10.             if ((numOk % i == 0)) {
  11.                 if (i == min)
  12.                 {
  13.                     running = false;
  14.                 }
  15.             }
  16.             else break;
  17.         }
  18.  
  19.         numOk++;
  20.     }
  21.  
  22.     return numOk - 1;
  23. }
  24.  
  25. // Example usage:
  26. MessageBox.Show(LCM(1, 20).ToString());

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month
-->