-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from Ayushparikh-code/gcdof2no
added Gcdof2no
- Loading branch information
Showing
1 changed file
with
30 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,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; | ||
} | ||
} |