Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

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;
    }
Comment

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;
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: unity3d find y position on navmesh 
Csharp :: c# read csv file 
Csharp :: checking if character is a digit or not in c# 
Csharp :: c# get last day of month 
Csharp :: C# Http.HttpRequestMessage 
Csharp :: how to read particular line of file in c# 
Csharp :: unity gui text 
Csharp :: c# multiple strings are empty 
Csharp :: on collision enter by layer 2d unity 
Csharp :: generate certificate in windows 
Csharp :: long number multiplication 
Csharp :: unity create 3d object in script 
Csharp :: Long, Max and Min value 
Csharp :: mongodb driver c# nuget 
Csharp :: unity camera follow with lerp 
Csharp :: c# how to check for internet connectivity 
Csharp :: columndefinition wpf 
Csharp :: c# close program 
Csharp :: unity toint 
Csharp :: Get the Photon Player GameObject 
Csharp :: cs string to enum 
Csharp :: map user to ConnectionId SignalR 
Csharp :: deserialize json to dynamic object c# 
Csharp :: unity get pivot position 
Csharp :: yield in c# 
Csharp :: c# modify dictionary in loop 
Csharp :: on collision unity 
Csharp :: why is called c# 
Csharp :: set the page that FormsAuthentication.RedirectFromLoginPage redirects to 
Csharp :: singleton pattern c# 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =