The document describes a Python program to find the greatest common divisor (GCD) of two numbers. It takes in two numbers as input, finds the smaller of the two, then iterates from 1 to the smaller number to find the largest integer that divides both numbers. It prints out the GCD. The sample output shows the program calculating the GCD of 24 and 15 to be 3. In conclusion, the Python GCD program was executed successfully.
The document describes a Python program to find the greatest common divisor (GCD) of two numbers. It takes in two numbers as input, finds the smaller of the two, then iterates from 1 to the smaller number to find the largest integer that divides both numbers. It prints out the GCD. The sample output shows the program calculating the GCD of 24 and 15 to be 3. In conclusion, the Python GCD program was executed successfully.
The document describes a Python program to find the greatest common divisor (GCD) of two numbers. It takes in two numbers as input, finds the smaller of the two, then iterates from 1 to the smaller number to find the largest integer that divides both numbers. It prints out the GCD. The sample output shows the program calculating the GCD of 24 and 15 to be 3. In conclusion, the Python GCD program was executed successfully.
The document describes a Python program to find the greatest common divisor (GCD) of two numbers. It takes in two numbers as input, finds the smaller of the two, then iterates from 1 to the smaller number to find the largest integer that divides both numbers. It prints out the GCD. The sample output shows the program calculating the GCD of 24 and 15 to be 3. In conclusion, the Python GCD program was executed successfully.
Python program to find GCD of two numbers Algorithm:
1. Read two numbers from users x and y
2. Find the smallest among the two inputs x and y 3. Repeat the following steps until i reaches smaller+1, then goto step 4 3.1 Check if x and y are divisible by i. 3.2 If it is True then, Assign gcd=i 4. Print the value of gcd
Program:
x = int(input("Enter first number: "))
y = int(input("Enter second number: ")) if x < y: smaller = x else: smaller = y for i in range(1, smaller+1): if((x % i == 0) and (y % i == 0)): gcd = i print "The GCD. of", x,"and", y,"is",gcd
Sample output:
/usr/bin/python3.4 /home/student/Desktop/fdrive/Exp1.py Enter first number: 24
Enter second number: 15
The GCD. of 24 and 15 is 3
Conclusion:
Thus the Python program to compute GCD of two numbers has been executed successfully.