24 bytes

  • HOME
  • Algorithms
    blue
  • Bubble Sort
  • Bucket Sort
  • Insertion Sort
  • Selection Sort
  • Merge Sort
  • Quick Sort
  • Heap Sort
  • Counting Sort
  • Stack
  • Queue
  • Double Linked List
  • Binary Search Tree
  • Towers OF Hanoi

  • Java Programs
    green bullet
  • Download RMI Calculator
  • Download file
  • Clock applet
  • File Upload
  • JDOM Parser
  • Client server
  • Udp Client server
  • Sudoku Solver

  • System Programming
  • Newtwork Sniffer
  • Good Links
    green bullet
  • Free Source Code
  • Top Coder
  • Code Project
  • Learn Today
  • Concept
  • Intresting Programs
    green bullet
  • Prime Number
  • GCD Euclids
  • Permutations


  • Google
     
    Web 24bytes.com



    GCD (Greatest Common Divisor ) Euclids way
    public class GreatestCommonDivisor {
    
    //using euclid's way of calculating GCD
      static int greatestCommonDivisor(int a, int b) {
        int gdivisor = 1, divider, dividend;
        if (a < b) { // the one less is divisor the one greater is dividend
          divider = a;
          dividend = b;
        }
        else {
          divider = b;
          dividend = a;
        }
    
        if (dividend % divider == 0) { //its the GCD
          return divider;
        }
        else { //proceed further
          greatestCommonDivisor(divider, dividend % divider);
        }
        return gdivisor; //the GCD of the 2 numbers
      }
    
      public static void main(String args[]) {
        System.out.println(greatestCommonDivisor(5, 144));
      }
    }
    GCD (Greatest Common Divisor ) Euclids way
    
    
    request a code or suggestion


    Email:
    Category


    Google
     
    Web 24bytes.com
    . original template by Aran Down.