This problem is know as Clock angle problem where we need to find angle between hands of an analog clock at a given time.
Input: h = 12:00, m = 30.00 Output: 165 degree Input: h = 3.00, m = 30.00 Output: 75 degree
The idea is to take 12:00 (h = 12, m = 0) as a reference. Following are detailed steps.
1) Calculate the angle made by hour hand with respect to 12:00 in h hours and m minutes.
2) Calculate the angle made by minute hand with respect to 12:00 in h hours and m minutes.
3) The difference between two angles is the angle between two hands.
How to calculate the two angles with respect to 12:00?
The minute hand moves 360 degree in 60 minute(or 6 degree in one minute) and hour hand moves 360 degree in 12 hours(or 0.5 degree in 1 minute). In h hours and m minutes, the minute hand would move (h*60 + m)*6 and hour hand would move (h*60 + m)*0.5.
Exercise: Find all times when hour and minute hands get superimposed.
This article is contributed by Ashish Bansal. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Check if the door is open or closed
- Find two prime numbers with given sum
- Converting Decimal Number lying between 1 to 3999 to Roman Numerals
- Count number of squares in a rectangle
- Check if a number can be expressed as x^y (x raised to power y)
- Build Lowest Number by Removing n digits from a given number
- Find number of days between two given dates
- Find next greater number with same set of digits
- Count Possible Decodings of a given Digit Sequence
- Find the smallest number whose digits multiply to a given number n
- Count trailing zeroes in factorial of a number
- Find if two rectangles overlap
- Dice Throw | DP-30
- Sieve of Eratosthenes
- Program for Fibonacci numbers