Tuesday 13 February 2024

Class 11 CS Practical - 28

 

28 - Write a program in Python to compute the greatest common divisor of two integers.

import math

a=int(input("Enter first number: "))

b=int(input("Enter second number: ")) 

print("GCD/HCF of ",a,"and",b,"=",math.gcd(a,b))


Output:

Enter first number: 60

Enter second number: 48

GCD/HCF of  60 and 48 = 12


Enter first number: 24

Enter second number: 18

GCD/HCF of  24 and 18 = 6




No comments:

Post a Comment