Angle between hour and minute hands of analogue clock using C

Graphic showing clock

This is a very interesting clock angle problem where the C program described in this article calculates the angle between the hour-hand and the minute-hand of an analog clock. In this example program if the user enters the hour and minute, then it should output the angle between the hour-hand and the minute-hand.


Input: hour = 10 and minute = 10

Output: 115 degree

Calculation theory

The hour hand of a 12-hour analog clock turns 3600 in (12 x 60) minutes; in other words 0.50 per minute. Similarly, the minute hand would take 60 minutes to turn a complete 3600 (which is 60 per minute). The angle between the hour hand and minute hand is obtained by the difference between these angles.


Code walk-through

The code is simple and self explanatory. Angle between the hour hand and the minute hand is calculated at the below lines,

abs() library function is used to get the absolute value of the angle difference in angle = abs(hAngle - mAngle);

The below code section selects the smaller angle value from the two possible angle values,

Leave a Reply 1

Your email address will not be published. Required fields are marked *



Thank you for this article..