Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

lcm

//Java program to find LCM of two numbers
import java.util.Scanner;
public class lcm{	
public static void main(String[] args)	{	
//scanner class declaration		
Scanner sc = new Scanner(System.in);		
//input from the user				
System.out.print("Enter the first number : ");
int num1 = sc.nextInt();		//input from the user		System.out.print("Enter the second number : ");				int num2 = sc.nextInt();		//logic for finding lcm of both numbers                int i;		int a =(num1 > num2)? num1 : num2;		for(i = a ; i <= num1*num2 ; i=i+a)		{			if(i % num1 == 0 && i % num2 == 0)				break;		}		//printing result		System.out.println("LCM of "+num1+" and "+num2+" is : "+i);		//closing scanner class(not compulsory, but good practice)		sc.close();										}}
Comment

LCM

#include <stdio.h>

int main() {

    int n1, n2, i, gcd, lcm;

    printf("Enter two positive integers: ");
    scanf("%d %d", &n1, &n2);

    // loop to find the GCD
    for (i = 1; i <= n1 && i <= n2; ++i) {
        
        // check if i is a factor of both integers
        if (n1 % i == 0 && n2 % i == 0)
            gcd = i;
    }

    lcm = (n1 * n2) / gcd;

    printf("The LCM of two numbers %d and %d is %d.", n1, n2, lcm);
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Java :: write arraylist to outputstream java byte file 
Java :: wsl-allow-port 
Java :: Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "EXCEPTION": invalid identifier 
Java :: what is xml file in java 
Java :: how to avoid outside click of alerdialoge android 
Java :: signed and unsigned data types in java 
Java :: remove activity from recent list android 
Java :: scanner in = new scanner(system.in) meaning in java 
Java :: split() String android 
Java :: android dynamically create layer-list with item and shape site:stackoverflow.com 
Java :: factorial java recursion 
Java :: return vs break 
Java :: How to convert Javascript return value to String in Android 
Java :: java quote of the day 
Java :: manifest merger 
Java :: komplettes array ausgeben java 
Java :: interviewbit_java 
Java :: comvertir a java 
Java :: how to read returned arraylist from another class method 
Java :: Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, : java.util.zip.ZipException: invalid code -- missing end-of-block 
Java :: rstudio boxplot coloring 
Java :: adding matrix 
Java :: regex pattern for car plates 
Java :: intellij evaluate expression 
Java :: jagermeister price in bangalore 
Java :: java replace nans with 0 csv line 
Java :: gc algorithms java 8 
Java :: call method of another class without creating instance in java android 
Java :: method reference java 
Java :: expiry time of otp android 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =