angle between hour and minute

Solutions on MaxInterview for angle between hour and minute by the best coders in the world

showing results for - "angle between hour and minute"
Luis
25 Nov 2019
1// Angle between minute and hour hand.
2// formula is : (h*30 - m*5.5) thats it.
3//if angle is between 180 && 360 than minus it from 360; like if(angle > 180) ==> angle = 360 - angle;
4// and if angle is less than 0 that means negative than make it positive;
5#include <stdio.h>
6int main()
7{
8  double h, m, angle;
9  scanf("%lf %lf", &h, &m);     // input hour and minute;
10  angle = (h * 30) - (m * 5.5); // applying formula
11  if (angle < 0) // making postive if it is negative
12  {
13    angle = 0 - angle;
14  }
15  if (angle > 180 && angle < 360) // making angle in range
16  {
17    angle = 360 - angle;
18  }
19  printf("%0.6lf\n", angle);
20  return 0;
21}
similar questions
angle between two points