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

the distribututive property combines and to make multiplying whole numbers simpler
Erasmus wrote a new version of _____. a. the doxology b. the old testament c. the new testamentd) the entire bible
Things martin Luther kind did
Jacob would like to include an arrow in his newsletter to point to some important information. He should _____. 1. type several dashes and one bracket 2. crea
654,2.564,2.056,2.465 greastes to leasest
Which type of landforms form through tensions?
You have 52 inches of yellow ribbon and 64 red ribbon you want to cut the ribbons into pieces of equal length with no left overs
What is the definition of “media literacy”?
During the cold war, the doctrine that both the u.s. and the soviet union would be destroyed if either side surprised the other with a nuclear attack was called
In July paleontologist found 368 fossils at a dig in August she found about 14 fossils a per day is the number of fossils the paleontologist found in August pro