linux programe for finding GCD of two numbers
i am M.Sc. electronics student.please help me in constructing linux program for G.C.D. of two numbers.And also i want logic of this program
A trivial solution to find LCM is as follows:
if (a < b)
temp = a ;
a = b;
b = temp;
a = a - b ;
Here a and b are the input values to program
and the final value of a is the LCM
Then use this equation:
GCD * LCM = a * b
to find GCD.
Euclid's algorithm to find the greatest common divisor of two
positive integers, m and n. See D. Knuth 'The Art of Computer
Programming', Volume 1, page 2.
(1) Divide m by n and let r be the remainder.
(2) If r equals 0 the algorithm terminate; n is the answer.
(3) Set m to n, n to r and go back to step (1).
r=$(( $m % $n )) # (1) Divide m by n and let r be the remainder.
if [ $r -eq 0 ] # (2) If r equals 0 the algorithm terminate; n is the answer.
m=$n # (3) Set m to n, n to r and go back to step (1).
|All times are GMT -5. The time now is 08:39 PM.|