0% found this document useful (0 votes)
7 views1 page

#5

This C# program calculates the least common multiple (LCM) of numbers from 1 to 20. It uses a method to compute the greatest common divisor (GCD) to derive the LCM. The final LCM value is printed to the console.

Uploaded by

dayeka9841
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views1 page

#5

This C# program calculates the least common multiple (LCM) of numbers from 1 to 20. It uses a method to compute the greatest common divisor (GCD) to derive the LCM. The final LCM value is printed to the console.

Uploaded by

dayeka9841
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

using System;

using System.Collections.Generic;

namespace EulerProject
{
class Program
{
static void Main()
{
long a = 1, b = 2, num = 0; // --#5--
while (b <= 20)
{
num = CalculateLCM(a, b);
a = num;
b++;
}
Console.WriteLine(num);

static long CalculateLCM(long a, long b) // -#5-


{
long gcd = CalculateGCD(a, b);
long lcm = (a * b) / gcd;
return lcm;
}

static long CalculateGCD(long a, long b) // -#5-


{
while (b != 0)
{
long temp = b;
b = a % b;
a = temp;
}
return a;
}
}
}

You might also like