Write an algorithm to find gcd of two numbers

Historical development[ edit ] The Euclidean algorithm was probably invented centuries before Euclidshown here holding a compass. The Euclidean algorithm is one of the oldest algorithms in common use.

Write an algorithm to find gcd of two numbers

Suppose that each number in the table is divided by 7 to produced a quotient and a remainder. What is the same about the results of the division in each row? Common multiples and the LCM An important way to compare two numbers is to compare their lists of multiples.

Let us write out the first few multiples of 4, and the first few multiples of 6, and compare the two lists. The numbers that occur on both lists have been circled, and are called common multiples. The common multiples of 6 and 8 are 0, 12, 24, 36, 48,… Apart from zero, which is a common multiple of any two numbers, the lowest common multiple of 4 and 6 is These same procedures can be done with any set of two or more non-zero whole numbers.

A common multiple of two or more nonzero whole numbers is a whole number that a multiple of all of them. The lowest common multiple or LCM of two or more whole numbers is the smallest of their common multiples, apart from zero.

Hence write out the first few common multiples of 12 and 16, and state their lowest common multiple. Hence write down the LCM of 12, 16 and 24? Solution a The multiples of 12 are 12, 24, 36, 48, 60, 72, 84, 96,,… The multiples of 16 are 16, 32, 48, 64, 80, 96,,… Hence the common multiples of 12 and 16 are 48, 96, ,… and their LCM is Two or more nonzero numbers always have a common multiple — just multiply the numbers together.

But the product of the numbers is not necessarily their lowest common multiple. What is the general situation illustrated here? Solution The LCM of 9 and 10 is their product The common multiples are the multiples of the LCM You will have noticed that the list of common multiples of 4 and 6 is actually a list of multiples of their LCM Similarly, the list of common multiples of 12 and 16 is a list of the multiples of their LCM This is a general result, which in Year 7 is best demonstrated by examples.

In an exercise at the end of the module, Primes and Prime Factorisationhowever, we have indicated how to prove the result using prime factorisation. This can be restated in terms of the multiples of the previous section: On the other hand, zero is the only multiple of zero, so zero is a factor of no numbers except zero.

These rather odd remarks are better left unsaid, unless students insist. They should certainly not become a distraction from the nonzero whole numbers that we want to discuss. The product of two nonzero whole numbers is always greater than or equal to each factor in the product.Edit Article How to Find the Least Common Multiple of Two Numbers.

In this Article: Article Summary Listing all Multiples Using Prime Factorization Using the Grid or Ladder Method Using Euclid’s Algorithm Community Q&A A multiple is the result of multiplying a number by an integer.

The first half is "How do I find the GCD between two numbers?" Ignore for a minute (seriously) that every response on here so far boils down to "google for the algorithm. Logic to find HCF of two numbers using recursion in C programming.

Write a recursive function in C to find GCD (HCF) of two numbers. Learn C programming, Data Structures tutorials, exercises, examples, programs, hacks, tips and tricks online.

About GCD and LCM. GCD stands for Greatest Common Divisor.

Prerequisite Math Knowledge

GCD is largest number that divides the given numbers. GCD Example. Find the GCD of 45 and Step 1: Find the divisiors of given numbers: The divisiors of 45 are: 1, 3, 5, 9, 15, 45 The divisiors of 54 are: 1, 2, 3, 6, 9, 18, 27, 54 Step 2: Find the greatest number that these two lists share in common.

A simple way to find GCD is to factorize both numbers and multiply common factors. Basic Euclidean Algorithm for GCD The algorithm is based on below facts.

If we subtract smaller number from larger (we reduce larger number), GCD doesn’t change.

Number Theory - Euclid's Algorithm

So if we keep subtracting repeatedly the larger of two, we end up with GCD. Finding the GCD of three numbers? Ask Question.

write an algorithm to find gcd of two numbers

up vote 10 down vote favorite. 4. I have found an algorithm called the Binary GCD/Stein Algorithm which takes two non-negative integers and finds the greatest common factor of the two.

Is it correct to write gcd(a,b) if a.

How to write a C program to find the GCD of two numbers?