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
Write a program that uses the radix sort to sort 1000 random digits. Print the data before and after the sort. Each sort bucket should be a linked list. At the end of the sort, the

(i)  Consider a system using flooding with hop counter. Suppose that the hop counter is originally set to the "diameter" (number of hops in the longest path without traversing any

A graph G might be defined as a finite set V of vertices & a set E of edges (pair of connected vertices). The notation utilized is as follows: Graph G = (V, E) Consider the g

Explain the Abstract data type assertions Generally, ADT assertions translate into assertions about the data types which implement ADTs, which helps insure that our ADT impleme

Comp are two functions n 2    and  2 n  / 4  for distinct values of n.   Determine When s ec on d function b ec om es l a r g er th an f i r st functi

Which sorting algorithm is easily adaptable to singly linked lists? Simple Insertion sor t is easily adabtable to singly linked list.

Relation between the time and space complexities of an algorithm The examining of algorithm focuses on time complexity and space complexity. As compared to time analysis, the a

Binary: Each node has one, zero, or two children. This assertion creates many tree operations efficient and simple. Binary Search : A binary tree where each and every left

What are the things require to implement ADT Abstract data types are very useful for helping us understand the mathematical objects which we use in our computations but, of cou

You are supposed to do the following: Write a parallel implementation of the raytracer using pthreads. Measure and compare the execution times for (i) the sequential ver