/* Problem 4--Clock Angles
   Another very straightforward problem. */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

FILE *in, *out;

int main (int argc, char **argv);
double angle (int h, int m);

int main (int argc, char **argv) {

  int h, m;

 in = fopen ("prob4.in","r");
 out = fopen ("prob4.out","w");
 while (1) {
  fscanf (in,"%d %d",&h,&m);
  if (h==0 && m==0) break;
  fprintf (out,"At %d:%02d the angle is %.1f degrees.\n",h,m,
           angle(h,m));
 }
 fclose (in);
 fclose (out);
 return EXIT_SUCCESS;
}

/* angle computes and returns the angle between the hands */
double angle (int h, int m) {

  double ha, ma,
         a;

 ma = m * 6;   /* The difference between minutes is 6 degrees each */
 ha = (h%12) * 30 + ma/12;  /* The difference between hours is 30
                               degrees each, plus each time the minute
                               hand is advanced, the hour hand is
                               advanced by one-twelfth as much. */
 a = fabs (ma-ha);  /* The distance between the hands in degrees */
 return a > 180 ? 360-a : a;  /* Making sure we return the smaller angle
                                 between the hands */
}
