Determine the greatest common divisor, Data Structure & Algorithms

Determine the greatest common divisor (GCD) of two integers, m & n. The algorithm for GCD might be defined as follows:

While m is greater than zero:

If n is greater than m, swap m and n.

Subtract n from m.

n is the GCD

Code in C

int gcd(int m, int n)

/* The precondition are following: m>0 & n>0. Let g = gcd(m,n). */

{

while( m > 0 )

{

if( n > m )

{ int t = m; m = n; n = t; } /* swap m & n*/

/* m >= n > 0 */

m - = n;

}

return n;

}

Posted Date: 4/4/2013 6:17:40 AM | Location : United States







Related Discussions:- Determine the greatest common divisor, Assignment Help, Ask Question on Determine the greatest common divisor, Get Answer, Expert's Help, Determine the greatest common divisor Discussions

Write discussion on Determine the greatest common divisor
Your posts are moderated
Related Questions
I need a person who has a good background in using R. Studio? In adition, a person who is good in using algorithms.

Prim's algorithm employs the concept of sets. Rather than processing the graph by sorted order of edges, this algorithm processes the edges within the graph randomly by building up


The complexity of multiplying two matrices of order m*n and n*p is    mnp

Q. Compare and contrast various sorting techniques or methods with respect to the memory space and the computing time.

Read the scenario (Pickerings Properties). (a) List the functions of the system, as perceived by an external user. (b) List the external entities. Note that because we are mo

calculate gpa using an algorithm

Define the term - Array A fixed length, ordered collection of values of same type stored in contiguous memory locations; collection may be ordered in several dimensions.

Since memory is becoming more & cheaper, the prominence of runtime complexity is enhancing. However, it is very much significant to analyses the amount of memory utilized by a prog

A binary search tree is used to locate the number 43. Which of the following probe sequences are possible and which are not? Explain. (a) 61 52 14 17 40 43 (b) 2 3 50 40 60 43 (c)