GCD of Two Numbers Using Recursion || Lesson 35.3 || Python || Learning Monkey ||

  Рет қаралды 7,453

Learning Monkey

Learning Monkey

3 жыл бұрын

#python#learningmonkey#pythoncoding#placements#pythontutorials#pythoncourse#pythonforbeginners#pythonfordatascience#pythonfullcourse#pythonprogramming#pythonfreecourse
GCD of Two Numbers Using Recursion
In this class, we write a program to find GCD of Two Numbers Using Recursion.
GCD of Two Numbers
The reader should have prior knowledge of recursion. For practice, Click here.
These examples are very helpful in placement exams. Follow our placement training course to crack placement exams easily.
Take an example and understand the GCD of two numbers.
GCD means greatest common divisor.
Example:
The two numbers are 36 and 24.
The numbers 36 and 24 both are divisible by 2.
Both the numbers are divisible by 3.
In the same way, both the numbers are divisible by 4,6, and12.
Out of all the numbers that are dividing 36 and 24. 12 is the greatest number.
GCD of 36 and 24 is 12.
Logic
From the given numbers, identify the maximum and minimum numbers.
In our example maximum number is 36. and the minimum number is 24.
Do maximum number modulus minimum number.
34 % 24 = 12
Next time maximum number is considered 24, and output is considered the minimum number, i.e. 12.
24 % 12 = 0
Next time maximum number is 12, and the minimum is zero.
Repeat until the minimum number is zero.
12 % 0 stop.
We stop if the minimum number is zero. And the maximum number is taken as our output.
In our example, 12 is our output.
Analyze the program given below for better practice.
Program
num1=int(input("enter your first number"))
num2=int(input("enter your second number"))
if num1 lt num2:
minimum=num1
maximum=num2
else:
minimum=num2
maximum=num1
def gcd(maximum,minimum):
if minimum==0:
return maximum
else:
return gcd(minimum,maximum % minimum)
result=gcd(maximum,minimum)
print(result)
Link for playlists:
/ @learningmonkey
Link for our website: learningmonkey.in
Follow us on Facebook @ / learningmonkey
Follow us on Instagram @ / learningmonkey1
Follow us on Twitter @ / _learningmonkey
Mail us @ learningmonkey01@gmail.com

Пікірлер: 16
@satyaff4456
@satyaff4456 3 жыл бұрын
Bro... excellent explanation ♥️
@NafeelAohamedN-cp4iy
@NafeelAohamedN-cp4iy
Sir nice explanation thank you
@preparedfor3957
@preparedfor3957 2 жыл бұрын
nice bhai
@AftabUA
@AftabUA 2 жыл бұрын
Thanks you ❣️❣️
@aryankumar87771
@aryankumar87771 Жыл бұрын
you told what to do, but did not tell why to do
@shubhamdas6519
@shubhamdas6519 2 жыл бұрын
thanks a lot sir...you make it more ease
@AKS-gq6jr
@AKS-gq6jr 2 жыл бұрын
thank you
@satyaff4456
@satyaff4456 3 жыл бұрын
Bro naaku add vachindi..... Full ga chusaaa
@user-xv5rk3mq1s
@user-xv5rk3mq1s
Some parts aren't really visible sir
@SoloEsports7
@SoloEsports7
Mc explanation
Python Tutorials - Program To Find out the GCD of Two Positive Numbers
13:11
ПРОВЕРИЛ АРБУЗЫ #shorts
00:34
Паша Осадчий
Рет қаралды 7 МЛН
Jumping off balcony pulls her tooth! 🫣🦷
01:00
Justin Flom
Рет қаралды 28 МЛН
EVOLUTION OF ICE CREAM 😱 #shorts
00:11
Savage Vlogs
Рет қаралды 12 МЛН
Python - Greatest Common Divisor W/ Recursion
9:14
Wrt Tech
Рет қаралды 8 М.
Solve Any Pattern Question With This Trick!
57:20
Kunal Kushwaha
Рет қаралды 2,3 МЛН
GCD of Two Numbers In Python | Python Practice 11 | Newtum Solutions
3:25
Program To Calculate LCM Of Two Numbers | Python Tutorials
19:20
Amulya's Academy
Рет қаралды 62 М.
GCD - Euclidean Algorithm (Method 1)
14:38
Neso Academy
Рет қаралды 524 М.
Fibonacci Series In Java With Recursion - Full Tutorial (FAST Algorithm)
15:11
Fastest Way to Learn ANY Programming Language: 80-20 rule
8:24
Sahil & Sarra
Рет қаралды 808 М.