आपकी ऑफलाइन सहायता

BACK
49

सी प्रोग्रामिंग

149

पाइथन प्रोग्रामिंग

49

सी प्लस प्लस

99

जावा प्रोग्रामिंग

149

जावास्क्रिप्ट

49

एंगुलर जे.एस.

69

पी.एच.पी.
माय एस.क्यू.एल.

99

एस.क्यू.एल.

Free

एच.टी.एम.एल.

99

सी.एस.एस.

149

आर प्रोग्रामिंग

39

जे.एस.पी.





डाउनलोड पी.डी.एफ. ई-बुक्स
Core Java - Gcm And Lcm Of Two Numbers

विवरण :

कोई विवरण नहीं है |


सोर्स कोड :

import java.util.Scanner;

public class LCMGCD
{
public static void main(String args[])
{

int num1,num2,temp1,temp2,gcd=0,lcm;

System.out.print("Enter two numeric values : ");
Scanner enter = new Scanner(System.in);
num1 = enter.nextInt();
num2 = enter.nextInt();

temp1=num1;
temp2=num2;

if(temp1 == 0)
{
gcd=temp2;
}
else if(temp2 == 0)
{
gcd=temp1;
}
else
{
while(temp2 != 0)
{
if(temp1 > temp2)
{
temp1=temp1-temp2;
}
else
{
temp2=temp2-temp1;
}
gcd=temp1;
}
}
lcm = (num1*num2) / gcd ;
System.out.println("LCM of " + num1 + " and " + num2 + " is " + lcm);
System.out.println("GCD of " + num1 + " and " + num2 + " is " + gcd);

}
}

आउटपुट :

Enter two numeric values : 50
45
LCM of 50 and 45 is 450
GCD of 50 and 45 is 5