PDA

View Full Version : How to make a detailed GCD( greatest common divisor) java program.


kinnikuroy
Jul 21, 2013, 07:46 AM
our professor wanted me to make a program regarding gcd of (a,b)

I know it is easy but... our professor wanted an ouput exactly like this


ex. Gcd (40, 23)
OUTPUT:

40 = 23(1) + (17) 0 <= 17 < 23
23 = 17(1) + (6) 0 <= 6 < 17
17 = 6(2) + (5) 0 <= 5 < 6
6 = 5(1) + (1) 0 <= 1 < 5
5 = 1(5) + (0) 0 <= 0 < 1

thanks...

kinnikuroy
Jul 21, 2013, 02:32 PM
I mean this,

40 = 23(1) + (17); 0 <= 17 < 23
23 = 17(1) + (6) ; 0 <= 6 < 17
17 = 6(2) + (5) ; 0 <= 5 < 6
6 = 5(1) + (1) ; 0 <= 1 < 5
5 = 1(5) + (0) ; 0 <= 0 < 1