Skip to content

Increase recursive GCD #283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 2, 2017
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Others/GCD.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

public class GCD{

public static int gcd(int a, int b) {
public static int gcd(int a, int b) {

int r = a % b;
while (r != 0) {
Expand All @@ -12,4 +12,16 @@ public static int gcd(int a, int b) {
}
return b;
}
public static int gcd(int[] number) {
int result = number[0];
for(int i = 1; i < number.length; i++)
result = gcd(result, number[i]);

return result;
}

public static void main(String[] args) {
int[] myIntArray = {4,16,32};
System.out.println(gcd(myIntArray));
}
}