Horje
Lcm of numbers Code Example
lcm of two numbers
#include <stdio.h>
int main() {
    int n1, n2, max;
    printf("Enter two positive integers: ");
    scanf("%d %d", &n1, &n2);

    // maximum number between n1 and n2 is stored in max
    max = (n1 > n2) ? n1 : n2;

    while (1) {
        if (max % n1 == 0 && max % n2 == 0) {
            printf("The LCM of %d and %d is %d.", n1, n2, max);
            break;
        }
        ++max;
    }
    return 0;
}
Lcm of numbers
    // call this function
    public static int LCM(List<int> input) 
    {
         int result = input[0];
         for (int i = 1; i < input.Count; i++) 
         {
            result = lcm(result, input[i]);
         }
         return result;
    }

    private static int LCM(int a, int b) 
    {
        return a * (b / gcd(a, b));
    }
	private static int gcd(int a, int b) 
    {
        while (b > 0) 
        {
            int temp = b;
            b = a % b; // % is remainder
            a = temp;
        }
        return a;
    }

    private static int gcd(List<int> input) 
    {
        int result = input[0];
        for (int i = 1; i < input.Count; i++) 
        {
            result = gcd(result, input[i]);
        }
        return result;
    }




Csharp

Related
visual studio pre build event not working Code Example visual studio pre build event not working Code Example
C# milisecond to h m s Code Example C# milisecond to h m s Code Example
how do you search for how many times a character appears in user input on c sharp Code Example how do you search for how many times a character appears in user input on c sharp Code Example
c# asqueryable select Code Example c# asqueryable select Code Example
mvc client validation doen't work display none Code Example mvc client validation doen't work display none Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9