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

c语言计算时针的夹角

发布时间: 2022-06-20 04:03:45

c语言计算指针夹角

你的输入函数的格式字符串写错了
应该是 %d 而不是 d%

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

❸ 用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语言计算时钟夹角问题

程序可以计算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>
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<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语言相关

#include <stdio.h>
#include <math.h>
int main()
{
int a,b;
float s;
printf ("Please input time:");
scanf("%d%d",&a,&b);
if ((b*6-(a%12)*30-b*1.0/60*30)>=0)
{s=b*6-(a%12)*30-b*1.0/60*30;
if (s>=180)
printf ("At %d:%02dthe angle is %.1f degrees.\n",a,b,(360-s));
else
printf ("At %d:%02d the angle is %.1f degrees.\n",a,b,s);
}
else if ((b*6-(a%12)*30-b*1.0/60*30)<0)
{s=(a%12)*30+b*1.0/60*30-b*6;
if (s>=180)
printf ("At %d:%02d the angle is %.1f degrees.\n",a,b,(360-s));
else
printf ("At %d:%02d the angle is %.1f degrees.\n",a,b,s);
}
else
printf ("Wrong.\n");
return 0;
}
我帮你改了下。你试试!

❽ c语言中求时钟夹角的代码

能不能把问题描述得更详细点?
秒针指向s就与12点逆时针成6*s度
分针指向m就与12点逆时针成6*m + s/10 度
时针指向h就与12点逆时针成30*h + m/2 + s/120 度
然后计算度数差值。大概思路应该是这样。

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

应该写成 11.0/2 吧

除号应该是 / 不是 \

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