-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import java.util.*; | ||
public class Program | ||
{ | ||
public static void main(String[] args) | ||
{ | ||
Scanner scn=new Scanner(System.in); | ||
int n1=scn.nextInt(); | ||
int n2=scn.nextInt(); | ||
int n3=n1;//storing value if n1 as it is needed in the as we change the value of it in while. | ||
int n4=n2;//storing values of n2 as it will be needed after as we change values for it in while function. | ||
if(n2>n1) | ||
{ | ||
while(n2%n1!=0) | ||
{ | ||
int rem=n2%n1; | ||
n2=n1; | ||
n1=rem; | ||
} | ||
System.out.println(n1+" is the GCD for the two given numbers "+n3+"and"+n4); | ||
int lcm=n3*n4/n1; | ||
System.out.println(lcm+" is the LCM of the two numbers "+n3+"and"+n4); | ||
} | ||
else | ||
{ | ||
while(n1%n2!=0) | ||
{ | ||
int rem=n1%n2; | ||
n1=n2; | ||
n2=rem; | ||
} | ||
System.out.println(n2+" is the GCD for the two given numbers."); | ||
int lcm=n3*n4/n2; | ||
System.out.println(lcm+" is the LCM of the two numbers "+n3+" and "+n4); | ||
} | ||
|
||
|
||
} | ||
|
||
} |