Determine the greatest common divisor, Data Structure & Algorithms

Assignment Help:

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;

}


Related Discussions:- Determine the greatest common divisor

Explain thread, Thread By changing the NULL lines in a binary tree to ...

Thread By changing the NULL lines in a binary tree to special links known as threads, it is possible to perform traversal, insertion and deletion without using either a stack

Explain the interfaces in ruby, Explain the Interfaces in Ruby Recall...

Explain the Interfaces in Ruby Recall that in object-oriented programming, an interface is a collection of abstract operations that cannot be instantiated. Even though Ruby i

A full binary tree with n leaves, A full binary tree with n leaves have:- ...

A full binary tree with n leaves have:- 2n -1 nodes.

Binary tree traversals, We have discussed already about three tree traversa...

We have discussed already about three tree traversal methods in the earlier section on general tree. The similar three different ways to do the traversal -inorder , preorder, and p

Process of channel access, Channel access In first generation systems, ...

Channel access In first generation systems, every cell supports a number of channels. At any given time a channel is allocated to only one user. Second generation systems also

Linked list, Write a program for reversing the Linked list

Write a program for reversing the Linked list

Prims algorithm, how to implement prims algorithm dynamically

how to implement prims algorithm dynamically

Variable length codes, Variable length codes (Niveau I) Code the following ...

Variable length codes (Niveau I) Code the following sequence of integers (2, 4, 2, 8, 3, 1, 4, 5, 13, 2) with • unary codes • ? codes • d codes • Rice codes (for a suitable l) and

Algorithm, what algorithms can i use for the above title in my project desi...

what algorithms can i use for the above title in my project desing and implmentation of road transport booking system

Write an algorithm for binary search., Write an algorithm for binary search...

Write an algorithm for binary search. Algorithm for Binary Search 1.  if (low> high) 2.  return (-1) 3.  Mid = (low + high)/2 4.  if ( X = = a[mid]) 5.  return (mid); 6.

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd