The greatest common divisor (GCD) of two or more numbers, which are not all zero, is the largest positive number that divides each of the numbers.
Input : 0.3, 0.9 Output : 0.3 Input : 0.48, 0.108 Output : 0.012
The simplest approach to solve this problem is :
Expressing each of the numbers without decimals as the product of primes we get:
Now, H.C.F. of 120 and 2250 = 2*3*5=30
Therefore,the H.C.F. of 1.20 and 22.5=0.30
(taking 2 decimal places)
We can do this using the Euclidean algorithm. This algorithm indicates that if the smaller number is subtracted from a bigger number, GCD of two numbers doesn’t change.
This article is contributed by Abhishek Sharma. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Sum of two large Floating-point numbers
- Smallest number to multiply to convert floating point to natural
- Fast method to calculate inverse square root of a floating point number in IEEE 754 format
- Check whether given floating point number is even or odd
- Pair of integers having least GCD among all given pairs having GCD exceeding K
- Program to find GCD or HCF of two numbers
- Program to find LCM of 2 numbers without using GCD
- Program to find GCD or HCF of two numbers using Middle School Procedure
- Rotation of a point about another point in C++
- Reflection of a point at 180 degree rotation of another point
- Print N lines of 4 numbers such that every pair among 4 numbers has a GCD K
- C++ Program for GCD of more than two (or array) numbers
- Java Program for GCD of more than two (or array) numbers
- Find the GCD of N Fibonacci Numbers with given Indices
- Find two numbers whose sum and GCD are given
- Find original numbers from gcd() every pair
- Python program to Find the Jumbo GCD subarray
- Program to find Greatest Common Divisor (GCD) of N strings
- Program to find the Break Even Point
- GCD of two numbers when one of them can be very large