Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <b> /** * Created with IntelliJ IDEA. * User: aniket * Date: 6/12/13 * Time: 4:46 PM * To change this template use File | Settings | File Templates. */ public class GCDFinder { public static int gcd( int a, int b){ int temp = a % b; if (temp == 0 ) return b; else return gcd(b,temp); } public static void main(String args[]){ System.out.println( "GCD of 12 and 10 is : " + gcd( 12 , 10 )); } } </b> |
Output :
GCD of 12 and 10 is : 2
Note : You can calculate LCM as Number1*Number2/GCD
No comments:
Post a Comment