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;
}
測試結果
全站熱搜