GCD using java
import
java.util.*;
class Gcd { public int calGCD(int a, int b) { if(a==0||b==0) return 0; if(a==b) return a; if(a>b) return calGCD((a-b),b); if(b>a) return calGCD(a,(b-a)); else return 0; } public static void main(String args[]) { Gcd obj=new Gcd(); System.out.println("Greatest Common Divisor is: "+obj.calGCD(35,5)); } } OutPut: |
0 comments:
Post a Comment