Answers for "angle between hour and minute"

C
0

angle between hour and minute

// Angle between minute and hour hand.
// formula is : (h*30 - m*5.5) thats it.
//if angle is between 180 && 360 than minus it from 360; like if(angle > 180) ==> angle = 360 - angle;
// and if angle is less than 0 that means negative than make it positive;
#include <stdio.h>
int main()
{
  double h, m, angle;
  scanf("%lf %lf", &h, &m);     // input hour and minute;
  angle = (h * 30) - (m * 5.5); // applying formula
  if (angle < 0) // making postive if it is negative
  {
    angle = 0 - angle;
  }
  if (angle > 180 && angle < 360) // making angle in range
  {
    angle = 360 - angle;
  }
  printf("%0.6lf\n", angle);
  return 0;
}
Posted by: Guest on August-02-2021

Code answers related to "angle between hour and minute"

Code answers related to "C"

Browse Popular Code Answers by Language