Using the consecutive Integer Checking Algorithm, solve the GCD of the following pair of numbers. (Show your complete solution.)
1. GCD (19, 7)
Find GCD(19, 7):
initial values: m = 19, n = 7
while n != 0 do : 7 != 0
r <- m mod n : r <- 19 mod 7 = 5
m <- n : m <- 7
n <- r : n <- 5
while n != 0 do : 5 != 0
r <- m mod n : r <- 7 mod 5 = 2
m <- n : m <- 7
n <- r : n <- 2
while n != 0 do : 2 != 0
r <- m mod n : r <- 5 mod 2 = 1
m <- n : m <- 2
n <- r : n <- 1
while n != 0 do : 1 != 0
r <- m mod n : r <- 2 mod 1 = 0
m <- n : m <- 1
n <- r : n <- 0
while n != 0 do : 0 == 0
return m : return 1
Comments
Leave a comment