Surviving the Technical Interview

Dr. Dobb's Journal Fall 1998

By Jay Sutaria

float time_angle (int hour, int minute) {
    float result;
    float hour_angle, minute_angle;
    /* mod minutes by 60, hour by 12 in case user */
    /* inputs high values */
    hour_angle = 0.5 * (float)((minute % 60) + 60 * 
                                     (hour % 12));
    minute_angle = 6 * (minute % 60);
    result = (hour_angle - minute_angle);
    /* make the result positive */
    if (result < 0) {
        result = result * -1;
    }
    return result;
}

Example 4: Calculating the angle between a clock's hour and minute hands.

Back to Article


Copyright © 1998, Dr. Dobb's Journal