时针与分针的夹角
#include <stdio.h>int main()
{
double a,b,d,e;
scanf("%lf %lf",&a,&b);
d = a*60.0;
e = (d+b)*0.5-b*6.0;
if (e>=180.0)
{
printf("%lf:%lf the angle is %lf degrees.\n",a,b,e-180.0);
}
else
printf("%lf:%lf the angle is %lf degrees.\n",a,b,e);
return 0;
}
求助我的输出一直是0
题目是时针与分针的夹角 你这计算夹角公式不对吧 wp231957 发表于 2021-8-28 08:03
你这计算夹角公式不对吧
主要我想问不管我输入什么,输出结果都得到0
a和b也是输出为0 TD1129 发表于 2021-8-28 08:15
主要我想问不管我输入什么,输出结果都得到0
a和b也是输出为0
scanf("%lf %lf",&a,&b);
自己的l容易错,你确认是小写的L吗 不知道你那里处理什么问题,我用你的程序,没有一直输出0.很可能是scanf导致的,你把两个%lf中间的空格去掉试试。
再者,你的计算式是不对的。
#include <stdio.h>
int main()
{
int a,b;
double c,d,e;
scanf("%d%d",&a,&b);
c=b*6.0;
d = a*30.0+c/12;
c-d>0 ?e=c-d:e=d-c;
if (e>180)
printf("%d:%d the angle is %lf degrees.\n",a,b,360-e);
else
printf("%d:%d the angle is %lf degrees.\n",a,b,e);
return 0;
}
页:
[1]