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 number 4,305,012 written in expanded notation
Some festivals last one or more weeks. What is the complete predicate? A. some festivals B. some festivals last C. last one or m
what is .000513 in scientific notation
Plz factor 2x^2+17x-21
What would most likely be included in the “Analysis” section of a lab report?
Is 810 divisible by 2,3,4,5,6,9,and 10
What right did the English nobles gain when King John signed the Magna Carta?
Who was daniel morgan and what role did he play in the american revolution?
Which is a recursive formula for the sequence 99.4, 0, –99.4, –198.8, where f(1) = 99.4?
Which document begins with the words "We the people of the United States"?