A. c語言求時針和分針的夾角
#include<stdio.h>
void main()
{
double m,h,a,b,c;
scanf("%lf:%lf",&h,&m);
a=m*6;
b=(h+m/60.0)*30;
c=360-b+a;
printf("c=%.lf\n",c);
}
B. C語言——求時針和分針的夾角
#include<stdio.h>
intmain(){
intT;
inth,m,s,re;
scanf("%d",&T);
while(T--){
scanf("%d%d%d",&h,&m,&s);
if(h>12)h=h-12;
re=(h/12.0*360+(m/60.0*360+s/60.0*360/60)/12)-(m/60.0*360+s/60.0*360/60);
if(re<0)re=re+360;
if(re>180)re=360-re;
printf("%d° ",(int)re);
}
}
C. 怎麼用C語言求時針與分針的角度
#include<iostream.h>
#include <math.h>
double angle(int hour,int min)
{
double h,m,ret;
h=(hour+min/60.0)*30;//時針的角度,每小時30度
m=6*min;//分針的角度,每分鍾6度
ret=fabs(h-m);
ret=ret>180?360-ret:ret;
return ret;
}
void main()
{
double h,m;
cout<<"enter hour(0~11) and minutes(0~59)";
cin>>h;
while(h<0||h>11)
{
cout<<"enter hour(0~11) and minutes(0~59)";
cin>>h;
}
cin>>m;
while(m<0||m>59)
{
cout<<"enter minutes(0~11) and minutes(0~59)";
cin>>m;
}
cout<<"the angle is:"<<angle(h,m)<<endl;
}
D. c語言 時鍾模擬
#include<math.h>
#include<dos.h>
#include<graphics.h>
#include<conio.h>
#include<time.h>
#define PI 3.141592653589793
int h,m,s,i,l,mon,y,d;
struct time t;
struct date data;
draw()
{
gettime(&t); //取得時間信息到t
s=t.ti_sec; //秒
h=t.ti_hour; //時
m=t.ti_min; //分
getdate(&data); //取得日期信息到data
y=data.da_year; //年
mon=data.da_mon; //月
d=data.da_day; //日
//畫出鍾的外圓(即是輪廓)
setcolor(11);
circle(300,200,152);
setcolor(3);
circle(300,200,157);
//畫出60個分鍾刻度
for(i=0;i<60;i+=1)
{
if(i%5==0) l=140;
else l=145;
line(300+150*sin(i*PI/30),200-150*cos(i*PI/30),
300+l*sin(i*PI/30),200-l*cos(i*PI/30));
}
//畫秒針
setcolor(19);
line(300,200,300+140*sin(s*PI/30),200-140*cos(s*PI/30));
//畫分針
setcolor(3);
line(300,200,300+110*sin(m*PI/30),200-110*cos(m*PI/30));
//畫時針
setcolor(11);
line(300,200,300+90*sin(((float)h+(float)m/60)*PI/6),200-90*cos(((float)h+(float)m/60)*PI/6));
//標注鍾盤上的"3"、"6"、"9"、"12"
settextstyle(3,0,2);
outtextxy(430,190,"3");
outtextxy(295,320,"6");
outtextxy(160,190,"9");
outtextxy(293,60,"12");
}
main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,""); //初始化屏幕模式
setbkcolor(8);
while(!kbhit()) //若有鍵盤輸入則跳出(結束程序)
{
draw(); //繪制鍾
settextstyle(3,0,5);
setcolor(9);
outtextxy(60,170,"my clock");
gotoxy(35,17);
//列印出數字形式的時間(hh:mm:ss)
if(h<10) printf("0");printf("%d:",h);
if(m<10) printf("0");printf("%d:",m);
if(s<10) printf("0");printf("%d",s);
gotoxy(33,18);
printf("%d:",y);
//列印出日期(mm:dd)
if(mon<10) printf("0");printf("%d:",mon);
if(d<10) printf("0");printf("%d",d);
sound(200); //讓喇叭以200HZ叫一聲
delay(70); //延時0.07秒,即是聲音延續0.07秒
nosound(); //停止聲音
sleep(1); //停止一秒
cleardevice(); //清屏
}
}
E. 分針與時針的夾角 C++
這應該挺簡單,我隨手幫你寫個
double getAngle(int hour, int minute){
double hour_degree = (hour+(minute/60)*(12/360);
double minute_degree = ( minute/60) * 360;
return fabs(hour_degree - minute_degree);
}