What's Here?
- Members: 99,792
- Replies: 389,624
- Topics: 58,613
- Snippets: 2,047
- Tutorials: 550
- Total Online: 1,620
- Members: 52
- Guests: 1,568
Who's Online?
|
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!
|
A brute-force method of getting the least common multiple in a range of numbers.
|
Submitted By: RodgerB
|
|
|
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
static uint LCM(int min, int max)
{
uint numOk = 1;
bool running = true;
while (running)
{
for (int i = max; i >= min; i--)
{
if ((numOk % i == 0)) {
if (i == min)
{
running = false;
}
}
else break;
}
numOk++;
}
return numOk - 1;
}
// Example usage:
MessageBox.Show(LCM(1, 20).ToString());
Copy & Paste
|
|
|
Reference Sheets
Bye Bye Ads
Free DIC T-Shirt
Related Sites
Monthly Drawing
Partners
Top Contributors
Top 10 Kudos This Month
|