c语言 时钟夹角问题

2024-12-28 17:20:13
推荐回答(2个)
回答1:

#include"stdio.h"
#include"math.h"
int main()

{ int x,y;
float z,w;
scanf("%d %d",&x,&y);
if(x!=12)
z=5.5*y-30*x;
if(x==12)
z=5.5*y;
if(z>=0)
w=z;
if(z<0)
w=0-z;
if(y<10)
printf("At %d:0%d the angle is %.1f degrees.\n",x,y,w);
if(y>=10)
printf("At %d:%d the angle is %.1f degrees.\n",x,y,w);
}

回答2:

#include
#include
int main()
{
int hour=1,minute=0;
float angle;re:
printf("Input the time(eg: 12:00):");
scanf("%d:%d",&hour,&minute);
if(hour>12||hour<0||minute>60||minute<0)
goto re;
angle=30*(float)hour-6*(float)minute;
if(angle<0)
angle-=angle*2;
printf("At %d:%d the angle is %.1f degrees.",hour,minute,angle);
getch();
return 0;
}