Presentation is loading. Please wait.

Presentation is loading. Please wait.

Recursive GCD Demo public class Euclid {

Similar presentations


Presentation on theme: "Recursive GCD Demo public class Euclid {"— Presentation transcript:

1 Recursive GCD Demo public class Euclid {
1/13/2019 public class Euclid { public static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } public static void main(String[] args) { int p = Integer.parseInt(args[0]); int q = Integer.parseInt(args[1]); System.out.println(gcd(p, q));

2 static int gcd(int p, int q) { if (q == 0) return p;
1/13/2019 p = 1272, q = 216 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(1272, 216)

3 static int gcd(int p, int q) { if (q == 0) return p;
1/13/2019 p = 1272, q = 216 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(1272, 216)

4 static int gcd(int p, int q) { if (q == 0) return p;
1/13/2019 p = 1272, q = 216 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(1272, 216)

5 static int gcd(int p, int q) { if (q == 0) return p;
1/13/2019 p = 1272, q = 216 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(1272, 216) 1272 = 216  p = 216, q = 192 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(216, 192)

6 static int gcd(int p, int q) { if (q == 0) return p;
1/13/2019 p = 1272, q = 216 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(1272, 216) p = 216, q = 192 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(216, 192)

7 static int gcd(int p, int q) { if (q == 0) return p;
1/13/2019 p = 1272, q = 216 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(1272, 216) p = 216, q = 192 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(216, 192)

8 static int gcd(int p, int q) { if (q == 0) return p;
1/13/2019 p = 1272, q = 216 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(1272, 216) p = 216, q = 192 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(216, 192) p = 192, q = 24 static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(192, 24) environment

9 static int gcd(int p, int q) { if (q == 0) return p;
1/13/2019 p = 1272, q = 216 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(1272, 216) p = 216, q = 192 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(216, 192) p = 192, q = 24 static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(192, 24) environment

10 static int gcd(int p, int q) { if (q == 0) return p;
1/13/2019 p = 1272, q = 216 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(1272, 216) p = 216, q = 192 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(216, 192) p = 192, q = 24 static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(192, 24) environment

11 static int gcd(int p, int q) { if (q == 0) return p;
1/13/2019 p = 1272, q = 216 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(1272, 216) p = 216, q = 192 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(216, 192) p = 192, q = 24 static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(192, 24) environment p = 24, q = 0 static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(24, 0) environment

12 static int gcd(int p, int q) { if (q == 0) return p;
1/13/2019 p = 1272, q = 216 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(1272, 216) p = 216, q = 192 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(216, 192) p = 192, q = 24 static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(192, 24) environment p = 24, q = 0 static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(24, 0) environment

13 static int gcd(int p, int q) { if (q == 0) return p;
1/13/2019 p = 1272, q = 216 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(1272, 216) p = 216, q = 192 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(216, 192) p = 192, q = 24 static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(192, 24) environment p = 24, q = 0 24 static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(24, 0) environment

14 static int gcd(int p, int q) { if (q == 0) return p;
1/13/2019 p = 1272, q = 216 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(1272, 216) p = 216, q = 192 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(216, 192) p = 192, q = 24 static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(192, 24) environment 24

15 static int gcd(int p, int q) { if (q == 0) return p;
1/13/2019 p = 1272, q = 216 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(1272, 216) p = 216, q = 192 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(216, 192) p = 192, q = 24 24 static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(192, 24) environment 24

16 static int gcd(int p, int q) { if (q == 0) return p;
1/13/2019 p = 1272, q = 216 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(1272, 216) p = 216, q = 192 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(216, 192) 24

17 static int gcd(int p, int q) { if (q == 0) return p;
1/13/2019 p = 1272, q = 216 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(1272, 216) p = 216, q = 192 environment 24 static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(216, 192) 24

18 static int gcd(int p, int q) { if (q == 0) return p;
1/13/2019 p = 1272, q = 216 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(1272, 216) 24

19 static int gcd(int p, int q) { if (q == 0) return p;
1/13/2019 p = 1272, q = 216 environment static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } gcd(1272, 216) 24 public class Euclid { public static int gcd(int p, int q) { if (q == 0) return p; else return gcd(q, p % q); } public static void main(String[] args) { int p = Integer.parseInt(args[0]); int q = Integer.parseInt(args[1]); System.out.println(gcd(p, q)); 24 24 % java Euclid 24


Download ppt "Recursive GCD Demo public class Euclid {"

Similar presentations


Ads by Google