airemalalaJerendos airemalalaJerendos
  • 10-12-2016
  • Computers and Technology
contestada

Design a recursive version of the Euclidean algorithm

Respuesta :

rsmith6559
rsmith6559 rsmith6559
  • 11-12-2016
Here's a recursive Python program that finds the greatest common denominator:

#!/usr/bin/python

import sys

def gcdR( x, y ):
    if( y ):
        return( gcdR( y, x % y ) )
    return x
       

if( __name__ == "__main__" ):
    x = max( int( sys.argv[ 1 ] ), int( sys.argv[ 2 ] ) )
    y = min( int( sys.argv[ 1 ] ), int( sys.argv[ 2 ] ) )

    print gcdR( y, x % y )

    sys.exit( 0 )


Answer Link

Otras preguntas

What is the slope of the line that contains the points (-8, 7) and (-4, -5)?
The _________ variable is the factor that changed as a result of the treatment applied through the independent variable. answer must be spelled correctly to rec
how does stress affect your driving
What were the two opposing opinions during the Iconoclastic Controversy?
Heart disease is a hereditary risk factor in Jamal's family. Describe and discuss what kinds of behavioral choices he could make to reduce his risk of developi
Which expression is equivalent to b^m/b^n ? A. bm-n B. bmn C. bm n D. bm+n
How to say happy birthday in korean with name?
Zeus Industries bought a computer for $2593. It is expected to depreciate at a rate of 30% per year. What will the value of the computer be in 3 years?
The graph of f(x) is shown below, if f(x) and its inverse function,
An element has six valence electrons available for bonding which group of the periodic table does this element most likely belong to