AndreiL
Welcome to AndreiL.
Enjoy your time.
Please log in.

GCD algorithm - Python

Go down

GCD algorithm - Python

Post by Lucaci Andrei on Mon Feb 13, 2012 5:37 am

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
'''
Created on Feb 3, 2012

@author: sin
'''
from fractions import gcd
a = input("a= ")
b = input("b= ")
x = a
y = b
while x <> y:
if x > y:
x = x - y
else: y = y - x

d = x
print "cmmcd (", a, ",", b, ")=", d, "."

'''Verification of the algorithm.'''
print gcd(a, b)
raw_input("Press <Enter>")

avatar
Lucaci Andrei
"Tata Lor"


Number of messages : 222
Points : 2266743
Reputation : 1007
Registration date : 2008-08-15
Age : 26
Location : Cluj-Napoca

View user profile http://www.andreil.wgz.ro

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum