# LCM and GCD program in Python

Compute the greatest common divisor(GCD) and least common multiple( LCM)of two integers. LCM and GCD / HCF program in python. This python project is useful for beginners and CBSE KV School Class 11 and Class 12 students computer science practical file and NIELIT O Level Programming and Problem Solving through Python (Module M3-R5).

### Objective- Compute the greatest common divisor and least common multiple of two integers using Python.

Highest Common Factor (HCF): The greatest common factor to any two or more than two integer numbers is known as HCF of those numbers. For example, HCF of 12 and 18 is 6. Also try:

Lowest Common Multiple (LCM): The smallest or lowest common multiple of any two or more than two integer numbers is termed as LCM. For example, LCM of 12 and 18 is 36.

### Source Code :

Screenshot of the source code

## Explaination of code :

def find_gcd(a,b): #function greatest common deviser taking a,b as input
gcd = 1 #Initialization
for i in range(1,a+1): #for loop
if a%i==0 and b%i==0: # checks for a divisor that divides both of a and b greater value will be come in gcd
gcd = i
return gcd
first = int(input(‘Enter first number: ‘)) #entering input
second = int(input(‘Enter second number: ‘))
print(‘HCF or GCD of %d and %d is %d’ %(first, second, find_gcd(first, second)))
lcm = first * second / find_gcd(first, second)
print(‘LCM of %d and %d is %d’ %(first, second, lcm))

## Output of LCM and GCD program in python

### Testing

Numbers are input 15 and 4. we know that HCF is 1 and LCM is 60.
Second number inputs are 20 and 15.we know HCF is 5 and LCM Is 60.
Both of the inputs are correct. Hence Testing is done.

### Result

The result is positive and objective is achieved.

Hello World Program in Python

Input a welcome message and display it in Python

Display the larger / smaller number in Python.

Greatest of Three Numbers in Python using Nested if

Patterns using nested loop in Python

Program to Print Pattern in Python

Program to input the value of x and n and sum of series in Python

Python Program for Armstrong, Prefect Number, Palindrome

Program of Prime number by recursion in python

Prime Number Program in Python

Write a Program to Print Fibonacci Series in Python

LCM and GCD program in Python

Python program to count number of vowels in a string

Whether a String is Palindrome or not in Python

Bubble Sort Program in Python

Linear search in python using list

Program to read a text file in python

Python program to read a file line by line

Program to Count Vowels and Consonants in Python

Stack Program in Python

Queue Program in Python

Python Leap Year Program for Beginners

Python Program to Print Series and Addition

Binary Search Program in Python

Program to find sum of digits in python

Sum of numbers divisible by 3 and 5 in python

Thanks for visit at Python Programs for Class 11 and 12 post.

error: Content is protected !!