C++ Program to Find GCD
source link: https://www.geeksforgeeks.org/videos/c-program-to-find-gcd/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
C++ Program to Find GCD
- 470 Views
- 06/06/2022
In this video, we will see a C++ program to find the GCD of two numbers. Basically, GCD (Greatest Common Divisor) or HCF (Highest Common Factor) of two numbers is the largest number that divides both of them.
For examples: Input: GCD of 98 and 56 is 14 Num 1 = “98” Num 2 = “56”
Then 98 = 2x7x7 56= 2x2x2x7
Common factor = 2x7 GCD = 14
To find GCD of two numbers we use three different methods: 1) Using loop 2) Using recursive function 3) Using In-built [ __GCD()] function
Apart from that, we will see the time and space complexity of each and every method. Here, - Time and space complexity will be O(N) & O(1) in looping method. - Using recursive function time and space complexity will be O(log(N)) & O(1) respectively. - And Using In-built [ __GCD()] function the time and space complexity will be O(log(N)) & O(1).
Program to find GCD of two numbers: https://www.geeksforgeeks.org/c-program-find-gcd-hcf-two-numbers/
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK