Skip to content

Commit

Permalink
Merge pull request #42 from Ayushparikh-code/gcdof2no
Browse files Browse the repository at this point in the history
added Gcdof2no
  • Loading branch information
unnati914 authored Jul 3, 2021
2 parents f45c3db + e334b8e commit e496358
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions gcdof2number.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* GCD Of Two Numbers In Java */
class Gcd
{
public static void main(String arg[])
{
long n1,n2;
Scanner sc=new Scanner(System.in);
System.out.println("enter number 1");
n1=sc.nextLong();
System.out.println("enter number 2");
n2=sc.nextLong();
if(n1>0 && n2>0)
{
long result=gcdCal(n1,n2);
System.out.println("Gcd of two numbers = "+result);
}
else
System.out.println("Please enter numbers greater than zero");
}
static long gcdCal(long a,long b)
{
while (b > 0)
{
long temp = b;
b = a % b;
a = temp;
}
return a;
}
}

0 comments on commit e496358

Please sign in to comment.