मराठी

Write program to print all common multiples of two numbers up to the product of the numbers.

Advertisements
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
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 11: Programs Overall - Loops [पृष्ठ २५१]

APPEARS IN

रूपा पंडित Computer Applications [English] Class 10 ICSE
पाठ 11 Programs Overall
Loops | Q 2. | पृष्ठ २५१
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×