1 / 19

Recursive GCD Demo

Recursive GCD Demo. 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 ) { System . out . println ( gcd ( 1272 , 216 )); } }.

Download Presentation

Recursive GCD Demo

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Recursive GCD Demo publicclass Euclid { public staticint gcd(int p,int q) { if(q ==0)return p; elsereturn gcd(q, p % q); } publicstaticvoid main(String[] args) { System.out.println(gcd(1272,216)); } }

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

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

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

  5. static int gcd(int p, int q){ if (q ==0) return p; else return gcd(q, p % q); } gcd(1272, 216) static int gcd(int p, int q){ if (q ==0) return p; else return gcd(q, p % q); } gcd(216, 192) p = 216, q = 192 p = 1272, q = 216 environment environment 1272 = 216  5 + 192

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

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

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

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

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

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

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

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

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

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

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

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

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

  19. static int gcd(int p, int q){ if (q ==0) return p; else return gcd(q, p % q); } gcd(1272, 216) p = 1272, q = 216 environment 24 publicclass Euclid { public staticint gcd(int p,int q) { if(q ==0)return p; elsereturn gcd(q, p % q); } publicstaticvoid main(String[] args) { System.out.println(gcd(1272,216)); } } % java Euclid 24 24 24

More Related