Write program to print all common multiples of two numbers up to the product of the numbers.
Advertisements
प्रश्न
Write program to print all common multiples of two numbers up to the product of the numbers.
कोड लेखन
Advertisements
उत्तर
import java.util.*;
class clCommon
{
void main()
{
Scanner sc = new Scanner(System.in);
int n1, n2;
System.out.print("Enter number1 : ");
n1 = sc.nextInt();
System.out.print("Enter number2 : ");
n2 = sc.nextInt();
System.out.println("Common Multiples of " +n1 + " & " + n2 + "are : ");
for(int m = Math.max(n1, n2); m<= n1 * n2; m++)
{
if(m%n1=0 && m%n2=0)
{
System.out.print("" + m);
}
}
}
}
Output:
Enter number 1 : 9
Enter number 2 : 15
Common Multiples of 9 & 15 are :
45 90 135
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
