当前位置:首页 » 编程语言 » c语言求时针分针的角度
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言求时针分针的角度

发布时间: 2022-05-10 17:21:04

⑴ 怎么用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;
}

⑵ C语言时钟角度(错哪了)

你这里面判断的情况没有考虑清楚
比如说11:05分的时候,你由于一直是用分针的角度去减去时针的角度,所以此时得到了一个负值。然而在负值的情况下还区分为大于180和小于180。这里你没有考虑到。
改完后程序如下:
#include"stdio.h"
int main(){
int a,b;
float c;
scanf("%d %d",&a,&b);
c=(b*6)-(30*a+b/2);
if (c<0) {
c=-c;
}
if (c>180)
{
c=360-c;
printf("At %d:%02d the angle is %.1f degrees.\n",a,b,c);
}
else
printf("At %d:%02d the angle is %.1f degrees.\n",a,b,c);
return 0;
}

⑶ 分针与时针的夹角 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);

}

⑷ c语言计算时钟夹角问题

程序可以计算0:00~23:59之间的任意时刻两针之间的夹角。

#include <stdio.h>

#include <math.h>

int main()

{int m,h;

float a,a1,a2;

scanf("%d%d",&h,&m);

a1=h%12*30+0.5*m; //时针每走1小时是30度,1分钟走0.5度

a2=6*m; //分针每走1分钟是6度

a=fabs(a1-a2); //夹角为二者之差的绝对值

printf("At %d:%d the angle is %.1f degrees. ",h,m,a);

return 0;

}

⑸ 用C语言写一个程序计算时钟的夹角

#include<stdio.h>
int main()
{int a,b;
float c,d,e,f;
scanf("%d %d",&a,&b);
c=30*(a+b/60.0);
d=6*b;
if(-180<=c-d&&c-d<=180)
if ((c-d)<=180&&(c-d)>=0)
e=(c-d);
else e=d-c;
else
if(c-d>0)
e=360-(c-d);
else e=360+(c-d);
if(0<=a&&a<=12&&0<=b&&b<=59)
printf("At %d:%02d the angle is %.1f degrees.\n",a,b,e);
else
printf("please putin numbles again");
}

⑹ 初学C语言 时针分针夹角中数据计算的问题

应该写成 11.0/2 吧

除号应该是 / 不是 \

11/2如果两边都是int类型,则结果会为int类型,也就是说没有小数部分, 11/2 =5 而不是 5.5

⑺ 如何计算时针与分针夹角的度数

计算规律:

1、当分针在时针前面,可以先算出分针走过的角度,再减去时针走过的角度,即可求出时针与分针夹角的度数。

2、当分针在时针后面,可以先算出时针过的角度,再减去分针走过的角度,即可求出时针与分针夹角的度数。

单独计算每一小块:

1、普通钟表相当于圆,其时针或分针走一圈均相当于走过360°角;

2、钟表上的每一个大格(时针的一小时或分针的5分钟)对应的角度是:

分针走过的角度为:55×6°=330°

时针走过的角度为:7x30°+55x0.5° = 237.5°

则时针与分针夹角的度数为:330° - 237.5° = 92.5°

⑻ 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语言求时针和分针的夹角

#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);
}