码迷,mamicode.com
首页 > 其他好文 > 详细

Practice1

时间:2014-12-17 23:53:11      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:blog   ar   io   sp   div   log   bs   cti   amp   

compute the angle between hour hand and minute hand

input:  hh:mm

output: out a float that means the angle of inferior arc

eg:

    03:00
    14:45

    output:

    90.00
    172.50

#include <stdio.h>

int main(int args, char* argv[]) {
    int h, m;
    scanf("%d:%d",&h,&m);
    if (h < 0 || h > 24 || m > 60 || m < 0) {
        return -1;
    }
    h %= 12;
    float hr = (h + (m/60.0f)) * 5;
    float r = (hr - m) ? (m - hr) * 6 : (hr - m) * 6;
    printf("%.2f", (360.00f - r)  > 180.00f ? (r): (360.00f - r));
    return 0;
}

 

 

Practice1

标签:blog   ar   io   sp   div   log   bs   cti   amp   

原文地址:http://www.cnblogs.com/lynnding/p/4170637.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!