Home > Programming > Finding GCD of given two numbers in Python

Finding GCD of given two numbers in Python


Here is a simple program to find the gcd of given two numbers. Here the procedure I’m using is simple logic that we have learned at our school level.

d1=int(raw_input("Enter a number:"))
d2=int(raw_input("Enter another number"))
rem=d1%d2
while rem!=0 :
    d1=d2
    d2=rem
    rem=d1%d2
print "gcd of given numbers is : %d" %(d2)

In the above program takes input from the command line using raw_input() (takes input as a string). And rest of the program is very simple. I run it in python shell it worked fine.

Advertisements
  1. kamil
    September 30, 2012 at 3:41 pm

    Super ……..

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: