HCF/GCD of Two numbers Using Python

  Рет қаралды 70,178

CodeWithHarry

CodeWithHarry

3 жыл бұрын

Calculation of HCF Using Python: In this video, we will learn to find the GCD of two numbers using Python. Python Program to Find HCF or GCD is asked very often in the exams and we will take this up in todays video!
Highest Common Factor or Greatest Common Divisor of two or more integers when at least one of them is not zero is the largest positive integer that evenly divides the numbers without a remainder. For example, the GCD of 8 and 12 is 4
►Python Practice Playlist: • Python Practice Progra...
►Checkout my English channel here: / programmingwithharry
►Click here to subscribe - / @codewithharry
Best Hindi Videos For Learning Programming:
►Learn Python In One Video - • Python Tutorial In Hin...
►Python Complete Course In Hindi - • Python Tutorials For A...
►C Language Complete Course In Hindi -
• C Language Tutorials I...
►JavaScript Complete Course In Hindi -
• JavaScript Tutorials I...
►Learn JavaScript in One Video - • JavaScript Tutorial
►Learn PHP In One Video - • Learn Php In One Video...
►Django Complete Course In Hindi -
• Python Django Tutorial...
►Machine Learning Using Python - • Machine Learning Tutor...
►Creating & Hosting A Website (Tech Blog) Using Python - • [Hindi] Web Developmen...
►Advanced Python Tutorials - • Intermediate/Advanced ...
►Object Oriented Programming In Python - • Object Oriented Progra...
►Python Data Science and Big Data Tutorials - • Python Data Science an...
Follow Me On Social Media
►Website (created using Flask) - www.codewithharry.com
►Facebook - / codewithharry
►Instagram - / codewithharry
►Personal Facebook A/c - / geekyharis
Twitter - / haris_is_here

Пікірлер: 229
@CodeWithHarry
@CodeWithHarry 3 жыл бұрын
Is playlist mei next video kya banau? Please suggest me some Python practice program topics? Python Practice Programs: kzbin.info/aero/PLu0W_9lII9agqZuv_XJen_BEHycIh-FmG C Practice Programs Playlist: kzbin.info/aero/PLu0W_9lII9ahSEQv6cHtu8JBXNgK2_QMX Instagram: instagram.com/codewithharry
@chamkaursingh7867
@chamkaursingh7867 3 жыл бұрын
Nice
@lakshyakumrawat
@lakshyakumrawat 3 жыл бұрын
Bhai pls cheat or hack any game using python
@AdarshSingh-cb5yf
@AdarshSingh-cb5yf 3 жыл бұрын
@@nakumgautam17 Ha bhai bahut jarurat hai mere ko bhi DS and Algo..... Lekin sir ne kai dino se vedio dala hi nhi 😕
@AdarshSingh-cb5yf
@AdarshSingh-cb5yf 3 жыл бұрын
Sir Ds and Algo please 😭😭😭😭... Bahut jarurat hai....
@shivankgarg1692
@shivankgarg1692 3 жыл бұрын
Bhai please DSA ki vdos upload krte raho
@hackerzone3292
@hackerzone3292 3 жыл бұрын
Yaar harry bhai...aapko ek salute bhai...hats off.. Mera aaj Data structure xam tha aaj...kuch bhi nai ata tha.. Sirf apki videos dek ke xam ko gaya hu bhai...aur 60-70mrks takk likh ke aya hu..sab aapke waja se bhai....dil se thanq soo much bhai...
@ankanderia4999
@ankanderia4999 2 жыл бұрын
def GCD(a,b): minNum = min(a,b) maxNum = max(a,b) rem = 1 while True: rem = maxNum % minNum if(rem == 0): break maxNum = minNum minNum = rem return minNum a = int(input("Enter first number : ")) b = int(input("Enter second number : ")) result = GCD(a,b) print(result) # we can do like that ...!!
@anshumangupta6594
@anshumangupta6594 3 жыл бұрын
Harry sir : legend in the house of you tube
@dhairyamehta8642
@dhairyamehta8642 3 жыл бұрын
very true
@atishayjain2205
@atishayjain2205 3 жыл бұрын
Bro when will you upload the next video for ds and algo playlist?
@kacharumanke7090
@kacharumanke7090 3 жыл бұрын
Such a great teacher, who is still working on 2 years old project.
@satyajitdas2780
@satyajitdas2780 3 жыл бұрын
Harry Praji! bahut sahi concepts with code hai? aise hi concepts wale videos banayiye jo interview mwi puchte ho, wo substring, subsequence, anagrams, catalon numbers, bhai how to identify recursion and solving by recursion! Bhai apse badiya koi nahi samjata hoin. Thank you Praji!
@hackerzone3292
@hackerzone3292 3 жыл бұрын
Ekdam matlb no words to describe u harry bhai....wat a talent...really fan of u...
@dhairyamehta8642
@dhairyamehta8642 3 жыл бұрын
best teacher ever meet
@dhairyamehta8642
@dhairyamehta8642 3 жыл бұрын
@Prince Raj : )
@mohitgupta2699
@mohitgupta2699 3 жыл бұрын
@Prince Raj can you please explain your code
@mohitgupta2699
@mohitgupta2699 3 жыл бұрын
@Prince Raj you are my teacher , explain me
@mohitgupta2699
@mohitgupta2699 3 жыл бұрын
I already solve it on the day when you uploaded the lcm using python video By the way awesome video
@codewithakshay7389
@codewithakshay7389 3 жыл бұрын
Sir lectures chal rahe hain college ke par yek like or view dene aaya hoon thanks Harry sir for wonderful videos of programming 😊😊💥💥💥💥
@29ibrahimsayed95
@29ibrahimsayed95 Жыл бұрын
What a lovely explanation
@anokhautomation4453
@anokhautomation4453 3 жыл бұрын
Very very useful 👍👍👍🎉🎉 Thanks
@dakshgarg775
@dakshgarg775 3 жыл бұрын
I am not first i am not last whenever i see your notification i click very fast
@dhairyamehta8642
@dhairyamehta8642 3 жыл бұрын
Nice one
@sonisinha8912
@sonisinha8912 3 жыл бұрын
Sir please make video series on unity game engine for game development and for game programming.....plz reply
@ganeshmirisker4173
@ganeshmirisker4173 2 жыл бұрын
super explanation bro ,maza aagaya
@dhairyamehta8642
@dhairyamehta8642 3 жыл бұрын
Superb video sir
@Boldunicorn
@Boldunicorn 3 жыл бұрын
Available with 3.9 and dict union ... beautiful feature, faster than previous
@skepticaluniverse7632
@skepticaluniverse7632 3 жыл бұрын
you are great bro hats off to you effort
@khadimhusen
@khadimhusen 3 жыл бұрын
Very good informative
@thecoderguy2110
@thecoderguy2110 3 жыл бұрын
Amazing Playlist
@mayankjoshi8104
@mayankjoshi8104 3 жыл бұрын
harry bhai face detecton or face recognition in python banado please..
@vardanbhaskar5222
@vardanbhaskar5222 3 жыл бұрын
Your videos are awesome bro:)
@hackerzone3292
@hackerzone3292 3 жыл бұрын
Thnq sm harry bhai...😍♥♥♥
@faiyazahmad21
@faiyazahmad21 3 жыл бұрын
Thank you so much Harry bhai
@devrajbhattacharya7912
@devrajbhattacharya7912 2 жыл бұрын
harry bhai thanku
@Shivanilodhi31
@Shivanilodhi31 2 жыл бұрын
thank you very helpful
@chahatvamdev4088
@chahatvamdev4088 3 жыл бұрын
VERY INTERSTING SIR
@abhayparihar6802
@abhayparihar6802 Жыл бұрын
Thank you so much bhai
@ritikjain6952
@ritikjain6952 3 жыл бұрын
Bhai plzzzzz Data structures and algorithms ki videos bhi upload kr do College teacher regularly takes class and he has completed 2 chapters (upto queue).....plzzzzzzzz
@dhairyamehta8642
@dhairyamehta8642 3 жыл бұрын
thank you so much sir
@prozeangamer4726
@prozeangamer4726 3 жыл бұрын
Herry bhai you are super 😎😎😎
@MK-lu4pe
@MK-lu4pe 3 жыл бұрын
Harry sir I am current in 10th. class 10th me maths ke 1st ch me HCF and LCM find karne ke bahut sare question he. isliye maine kam aasan karne ke liye HCF and LCM find karne ka Python program banaya tha. maine aapse hi python sikhi hai. Thank you so much Harry sir.
@MK-lu4pe
@MK-lu4pe 3 жыл бұрын
maine ye program pehle hi bana liya tha aapse hi Python sikh ke.
@MK-lu4pe
@MK-lu4pe 3 жыл бұрын
or maine Jarvis bhi banaya. jo meri konsi class kab suru hogi vo kehta hai and automatic browser open kar deta hai. itna hi nahi kab kya study karni hai or kab break lena hai vo sab time hote keh deta hai. me roj Jarvis update karta hu usme kuchh na kuchh new dalta rehta hu. dhire dhire real Jarvis ban raha hai. Thank you sir.
@sudarshanmhaisdhune1039
@sudarshanmhaisdhune1039 3 жыл бұрын
Great one vro!=
@RohanDasRD
@RohanDasRD 3 жыл бұрын
Great Video Brother
@__ayu
@__ayu Жыл бұрын
THANK YOU #CodeWithHarry
@pradeep_bhaiya2502
@pradeep_bhaiya2502 3 жыл бұрын
Cool harry bhai
@RitikKumar-kd9up
@RitikKumar-kd9up 3 жыл бұрын
Thanks sir for clearing my concept for this question
@mohitgupta2699
@mohitgupta2699 3 жыл бұрын
@Prince Raj can you please explain your code
@ayushmanglamsingh4505
@ayushmanglamsingh4505 3 жыл бұрын
Nice Video 🔥🔥
@mayanksandal
@mayanksandal Жыл бұрын
I have made my own code to find the HCF/GCD using sets in python.
@abhiaryan07
@abhiaryan07 3 жыл бұрын
Bro please make a video on how to improve typing speed.... Your typing speed is awesome...
@vathsan3906
@vathsan3906 3 жыл бұрын
Practice
@techmate8316
@techmate8316 2 жыл бұрын
Please also teach block based coding
@mdafroj8546
@mdafroj8546 Жыл бұрын
Thank you sir 😎😍💝😍
@sarcarpit
@sarcarpit 3 жыл бұрын
sir i tried it myself and i came up with a different logic . Please check if I m correct? a = int(input("Enter the first number : ")) b = int(input("Enter the second number : ")) hcf=1 i=min(a,b) while i>1: if a%i==0 and b%i ==0: hcf=i break i=i-1 print(f"The HCF of {a} & {b} is : {hcf} ") I have learnt Python from your channel only!! you're the BEST !!
@HARSHPIPAL
@HARSHPIPAL 3 жыл бұрын
Instead of updating the maximum value in for loop...we can simply run a loop in reverse direction from smaller number to 1.... correct?
@Pramod-wq7ef
@Pramod-wq7ef 2 жыл бұрын
I thought of the same approach bro...looping from the min no. till 1 and if there is any number divisible by both the given numbers, assign it as LCM and break the loop.
@dhairyamehta8642
@dhairyamehta8642 3 жыл бұрын
Nice video
@jagmohansaini6234
@jagmohansaini6234 3 жыл бұрын
Thanks sir
@sasorikun9815
@sasorikun9815 3 жыл бұрын
Harry bhaiya op......
@varshajawrani5153
@varshajawrani5153 3 жыл бұрын
Sir please continue java and data structure course playlist
@Pramod-wq7ef
@Pramod-wq7ef 2 жыл бұрын
Bro I have another approach, instead of looping from 1 till min number and updating hcf every time, we can loop from the min of two numbers till 1 and if we find a factor for both, we assign it as hcf and break the loop. I guess this approach might reduce the num of iterations.
@uttkarsh7823
@uttkarsh7823 2 жыл бұрын
true
@rickk3300
@rickk3300 2 жыл бұрын
What if the numbers are 16 and 18? Then your approach will take more number of iterations. The point is it doesn't matter from which side you iterate....
@SnehaR380
@SnehaR380 Жыл бұрын
Yup that's what I was thinking def hcf(a, b): smaller = min(a, b) hcf = 1 for i in range(smaller,0,-1): if a%i == 0 and b%i == 0: hcf = i break return hcf a=int(input("1st no. ")) b=int(input("2nd no. ")) print(hcf(a,b))
@SnehaR380
@SnehaR380 Жыл бұрын
@@rickk3300 I am always getting 1 as answer on using sir's code because I think since i=1 satisfies it foremost it gives 1 as output whereas when I did by another approach i am.ways getting right hcf Why so?
@SnehaR380
@SnehaR380 Жыл бұрын
@@uttkarsh7823 I guess sir's approach is wrong
@omlanguagestudiogermanlang6260
@omlanguagestudiogermanlang6260 2 жыл бұрын
thanks
@piyushbhardwaj9167
@piyushbhardwaj9167 3 жыл бұрын
Different types of patterns aur unki approach ko lekrr plzz plzz
@dhairyamehta8642
@dhairyamehta8642 3 жыл бұрын
you are awesome sir
@naturebgm-hz2zu
@naturebgm-hz2zu 6 ай бұрын
hcf undefined q show ho rha?
@nehamittal8310
@nehamittal8310 3 жыл бұрын
Please make tutorial series of kivy please reply
@abhibiranje9517
@abhibiranje9517 3 жыл бұрын
Sir your method is good but I have better method with time complexity num1=int(input("Enter firat number ")) num2=int(input("Wnter second number ")) if num1>num2: mn=num2 else: mn=num1 for i in range(1,int((mn/2)+1)): if num1%i==0 and num2%i==0: hcf=i if num2%num1==0: hcf=num1 print(f"Your HCF is {hcf}")
@uttkarsh7823
@uttkarsh7823 2 жыл бұрын
method dusra nahi hai, bas mn/2 kiya hai, but still, good
@tanmaydaga4518
@tanmaydaga4518 3 жыл бұрын
When I learned python from ur playlist I also made this for my school purpose but my logic was way to long than ours.
@uttkarsh7823
@uttkarsh7823 2 жыл бұрын
My logic also very long
@abheygupta2332
@abheygupta2332 3 жыл бұрын
Thanku sir
@faiyazahmad21
@faiyazahmad21 3 жыл бұрын
Harry bhai DBMS ka tutorial bna dijiye please
@bakchodilive4020
@bakchodilive4020 3 жыл бұрын
Sir please make the video of pc building for programing language
@niteshsharma595
@niteshsharma595 3 жыл бұрын
Make a motivational video.
@SnehTalks
@SnehTalks 3 жыл бұрын
Harrybhai mera ek question hai.. Apne jarvis vali video me bataya tha ki 'hum additional voices bhi run kara sakte hai ..' .. bt mene google pe bahot dhunda prr iska genuine solution muje nahi nhi mil rha... Kya aap please iss topic pe video baanyenge ki kese hum vo dono voices(david and zera) ke alawa additional voices kese aur kaha se use kara sakte hai ????... Plzz bhaiya kuch batana
@nareshgoyal1994
@nareshgoyal1994 3 жыл бұрын
Harry bhai GCD ko Euclid division wale method se krke samjha do bhai.. Bahut problem aa rahi hai smjhne me
@EzTechGyan
@EzTechGyan 3 жыл бұрын
Nice tutorial sir ❤️ Aap screen me konsa likhne ke liye kiska use krte ho???
@EzTechGyan
@EzTechGyan 3 жыл бұрын
Product Name bhi btaiye please 👍
@SnehaR380
@SnehaR380 Жыл бұрын
Anyone please help me out I think that for loop must be run in reverse order in order to get highest value otherwise code would just return I=1 because ultimately that's the first value which satisfies if condition So I think code she be like this def hcf(a, b): smaller = min(a, b) hcf = 1 for i in range(smaller,0,-1): if a%i == 0 and b%i == 0: hcf = i break return hcf a=int(input("1st no. ")) b=int(input("2nd no. ")) print(hcf(a,b))
@SnehaR380
@SnehaR380 Жыл бұрын
I ran the above code and it worked
@SnehaR380
@SnehaR380 Жыл бұрын
On the other hand if I wrote for I in range (1,smaller+1) it was always giving 1 as answer
@anshumanchoudhary2658
@anshumanchoudhary2658 2 жыл бұрын
import math math.gcd(40,12) output--4 this is right for gcd or not and why we are not using this , what is difference ?
@ashishkumarsharma2081
@ashishkumarsharma2081 Жыл бұрын
because the other program helps us understand the logic which this inbuilt function uses.
@saumyashrivastava7802
@saumyashrivastava7802 3 жыл бұрын
Bhaiya knsa laptop best hoga coding wgerh krne ke liye
@APStatus
@APStatus 3 жыл бұрын
# Find HCF Function def HCF(n1,n2): min = n1 while (True): if (n1 % min == 0 and n2 % min == 0): return min min -= 1 # Main function if __name__=="__main__": n1 = int(input("Enter The First Number : ")) n2 = int(input("Enter The Second Number : ")) n1, n2 = min(n1, n2), max(n1, n2) hcf = HCF(n1, n2) print(f"{n1} & {n2} HCF is {hcf}") # Abhishek Sharma
@jitendradashora8956
@jitendradashora8956 Жыл бұрын
def hcf(a, b): highest_common_factor = 1 for numbers in range(2, max(a, b)): if a % numbers == 0 and b % numbers == 0: highest_common_factor = numbers return highest_common_factor
@ashishkumarsharma2081
@ashishkumarsharma2081 Жыл бұрын
shouldn't u use min()?
@SnehaR380
@SnehaR380 Жыл бұрын
@@ashishkumarsharma2081 can u please help me out in my query I posted in comment section
@SnehaR380
@SnehaR380 Жыл бұрын
@@ashishkumarsharma2081 btw u sing really good man
@shivanshutyagi83
@shivanshutyagi83 3 жыл бұрын
Harry bhai 👋👋
@_ARIC_KAJI
@_ARIC_KAJI 3 жыл бұрын
sir ji how to make a gui program that you enter the data in entry box and you click the button print your data is print in the hard copy . like this Name : harry bhai sir ji please reply
@shubhamteredesai8692
@shubhamteredesai8692 3 жыл бұрын
Harry bhai javascript mein phone keliye apps kaise banaye pl ek video banao
@acromatixgamer2291
@acromatixgamer2291 3 жыл бұрын
please teach us how to make a shooting game
@ayushmourya812
@ayushmourya812 3 жыл бұрын
Harry bhai DS algo ki next video laaloooooooo.
@prince6727
@prince6727 3 жыл бұрын
Sir Hardy Ramanujan number ke liye program banayi please
@creationduwal
@creationduwal 3 жыл бұрын
harry bhai math.gcd se bhi ho sakta hai na
@avibro7454
@avibro7454 3 жыл бұрын
Plz make a advance video for problem solving and making psudo code plzplzplzplzllz🙏🙏🙏🙏🙏
@dhairyamehta8642
@dhairyamehta8642 3 жыл бұрын
kitni bar dill jetoge sir
@mdfarman9786
@mdfarman9786 2 жыл бұрын
I can get LCM numbers from input using python
@creativeakshara8438
@creativeakshara8438 3 жыл бұрын
HARRY BHAI EK HEART DEDO I LOVE YOU BROTHER ♥️♥️
@shivanshgoyal310
@shivanshgoyal310 3 жыл бұрын
🔥🔥🔥
@RohanSharma-tf3rw
@RohanSharma-tf3rw 3 жыл бұрын
Harry bhai laptop bataiye hp 15s du2067tu plz bataiye kaisa h student or coding ke liye
@sannidhyakushwaha2561
@sannidhyakushwaha2561 3 жыл бұрын
Bro make playlist on Flutter app development.
@devashishprajapati9860
@devashishprajapati9860 3 жыл бұрын
Sir ji e commerces website per series banao
@ramavhad3586
@ramavhad3586 3 жыл бұрын
React ka playlist bana do sir from atharva
@dhairyamehta8642
@dhairyamehta8642 3 жыл бұрын
Get ready for 1M subscribers : )
@AKBMW-yh5ti
@AKBMW-yh5ti 3 жыл бұрын
Done
@studies3943
@studies3943 2 жыл бұрын
# Here is a simpler way: a = int(input("Enter first:")) b = int(input("Enter second:")) while a % b != 0: remainder = a % b a = b b = remainder print("HCF is:", b)
@Mahnoor529
@Mahnoor529 Жыл бұрын
Can u explain this plaese
@dhairyamehta8642
@dhairyamehta8642 3 жыл бұрын
5G se bhi fast video dalte ho sir
@rahulchaudhary5636
@rahulchaudhary5636 3 жыл бұрын
Bhai c practice video ni aayengi ab ?
@JADE2238
@JADE2238 3 жыл бұрын
Harry Potter bhai 😂 make a tutorial on unreal engine 4
@rajatsirvlog
@rajatsirvlog 3 жыл бұрын
Harry bhae Python se kivy tutorial bnao please let
@Lila12386
@Lila12386 3 жыл бұрын
Python guru
@radhapatel8536
@radhapatel8536 2 жыл бұрын
My program: a = int(input("Enter n: " )) l1 = [ ] for i in range(1,a+1): b = int(input("Enter the number: ")) l1.append(b) c = int(min(l1)) # HCF for i in range(1, c+1): for numbers in l1: if numbers%i == 0: HCF = i print("The HCF is " , HCF)
@uttkarsh7823
@uttkarsh7823 2 жыл бұрын
wrong code, let me correct your code and send you the correct one..
@radhapatel8536
@radhapatel8536 2 жыл бұрын
@@uttkarsh7823 print("Enter two numbers to calculate HCF ") a=int(input("Enter first number ")) b=int(input("Enter second number ")) while a%b !=0: rem=a%b a=b b=rem print("HCF is ", b)
@uttkarsh7823
@uttkarsh7823 2 жыл бұрын
@@radhapatel8536 yes, now correct, good
@omkarsingh3702
@omkarsingh3702 3 жыл бұрын
Harry if we are in 9th class can we learn artificial intelligence or machine learning please tell me
@Pramod-wq7ef
@Pramod-wq7ef 2 жыл бұрын
it depends on what you want to acheive after learning bro
@someshsangwan5302
@someshsangwan5302 2 жыл бұрын
this code will shoe error if we takes input (0,b) here b is any number : def gcd(self, A, B): if A > B: smaller = B bigger=A else: smaller = A bigger=B if smaller==0: return bigger for i in range(1, smaller+1): if((A % i == 0) and (B % i == 0)): k=i return k
@aditgaur1585
@aditgaur1585 3 жыл бұрын
11:26 Code With Eminem 😂
@lakshyakumrawat
@lakshyakumrawat 3 жыл бұрын
Bhai pls cheat or hack any game using python
@pranjalkhatri5631
@pranjalkhatri5631 3 жыл бұрын
Tensorflow tutorial
@AmaanKhan-cb4rn
@AmaanKhan-cb4rn 11 ай бұрын
❤❤
@Secret_Superstar_Girl
@Secret_Superstar_Girl 3 жыл бұрын
Bhaiya by learning python how much salary job we can get .
@premsiddhu4891
@premsiddhu4891 3 жыл бұрын
First like
Python Tutorials - Program To Find out the GCD of Two Positive Numbers
13:11
Опасность фирменной зарядки Apple
00:57
SuperCrastan
Рет қаралды 12 МЛН
Heartwarming Unity at School Event #shorts
00:19
Fabiosa Stories
Рет қаралды 25 МЛН
Ouch.. 🤕
00:30
Celine & Michiel
Рет қаралды 26 МЛН
小蚂蚁被感动了!火影忍者 #佐助 #家庭
00:54
火影忍者一家
Рет қаралды 36 МЛН
GCD - Euclidean Algorithm (Method 1)
14:38
Neso Academy
Рет қаралды 524 М.
Logic Building in Programming - 5 Proven Strategies (2024) 🔥
13:01
CodeWithHarry
Рет қаралды 372 М.
Python Program #25 - Find HCF or GCD using Loop in Python
7:40
Programming For Beginners
Рет қаралды 2,5 М.
Program To Calculate LCM Of Two Numbers | Python Tutorials
19:20
Amulya's Academy
Рет қаралды 62 М.
Solve any Star Pattern program in Python
18:44
Simply Coding
Рет қаралды 904 М.
GCD of Two Numbers In Python | Python Practice 11 | Newtum Solutions
3:25
Which Operating System I use and Why 💻
14:57
CodeWithHarry
Рет қаралды 44 М.
Опасность фирменной зарядки Apple
00:57
SuperCrastan
Рет қаралды 12 МЛН