GCD

GCD
public class GCD{
 public void printGCD(int n,int m)
 {
  System.out.println(""+getGCD(n,m));
 }

 public int getGCD(int n,int m){
     int max,gcd;
     if(n>m)
      max=n;
     else
      max=m;
     for(int i = max;i>=1;i--){
      if(n%i==0 && m%i==0)
      {
               return i;
      }
     }
     return 1;
 }
}


Reactions

Post a Comment

0 Comments