For example, a GCD (greatest common divisor) algorithm is given on the right side. Below is the system implemented by using Python, where the % operator is the modulo operation that returns the remainder of a division: |
|
|
|
#!/usr/bin/python # # Python code to demonstrate a naive method # GCD (greatest common divisor) using Euclidean algorithm # import cgi # CGI module form = cgi.FieldStorage( ) # Reads the HTML form data. act = form["act"].value a = form["a" ].value b = form["b" ].value if ( act == "Find GCD( a, b )" ): # Print HTML. print( "Content-type: text/html\n\n" ) # Command issued: print( "/usr/bin/python GCD.py " + a + " " + b ) print( "GCD( " + a + ", " + b + " ) = " ) a = int( a ) b = int( b ) while( b ): a, b = b, a % b print( abs( a ) ) |
“I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones.” ― Albert Einstein |