close

心血來潮寫了個簡單小程式

user輸入小時與分鐘 , 程式自動計算時針與分針的角度 ( 夠簡單吧  ^+++^ )

程式碼

#include "stdafx.h"
#include "string.h"
#include <stdio.h>
#include <stdlib.h>

int _tmain(int argc, _TCHAR* argv[])
{
    int iHr;
    int iMin;
    int iDegree;

    printf("Please keyin Hour (1~12) : ");
    scanf("%d",&iHr);

    printf("Please keyin Minute (0 ~ 59) : ");
    scanf("%d",&iMin);
    
    // 360 / 12 = 30 (HR)
    // 360 / 60 = 6  (Min)

    iHr *= 30;
    iMin *= 6;
    iDegree = (iHr-iMin);
    if( iDegree > 180 )
    {
        iDegree = (360-iDegree);
    }
    printf("Degree : %d\n",iDegree);

    system("pause");
    
    return 0;
}

測試結果

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Crystina 的頭像
    Crystina

    Christine's Memo

    Crystina 發表在 痞客邦 留言(0) 人氣()