请高手检查一下C语言编的简单程序中的语法错误

来源:百度知道 编辑:UC知道 时间:2024/05/29 22:08:43
背景:

钟面上的时针和分针之间的夹角总是在 ~之间 ( 包括 和 ) 。举例来说,在十二点的时候两针之间的夹角为 ,而在六点的时候夹角为 ,在三点的时候为 。本题要解决的是计算 12:00 到 11:59 之间任意一个时间的夹角。

输入:

每组测试数据包含两个数字:第一个数字代表小时 ( 大于 0 小于等于 12) ,第二个数字代表分 ( 在区间 [0, 59] 上 ) 。

输出:

对应每组测试数据,用常用格式显示时间以及这个时候时针和分针间的最小夹角,精确到小数点后一位。输出格式如下所示。

#include <stdio.h>
void main()
{
int a,b;
scanf("%d%d",&a,&b);
if(30*a>=b/60*30&&30*a-b/60*30<=180) printf("At %d:%2d the angle is %.1f degrees.\n
",a,b,30*a-b/60*30);
else if(30*a>=b/60*30&&30*a-b/60*30>=180) printf("At %d:%2d the angle is %.1f degrees.\n
",a,b,360-(30*a-b/60*30));
else if(30*a<=a/60*30&&b/60*30-30*a<=180) printf("At %d:%2d the angle is %.1f degrees.\n
",a,b,b/60*30-30*a);
else if(30*a<=b/60*30&&b/60*30-30*a>=180) printf("At %d:%2d the angle is %.1f degrees.\n
",a,b,360-(60*30-30*a));<

试试这个:
#include<stdio.h>

main()
{
int a,b;

float c;

clrscr();

scanf("%d:%d",&a,&b);

if(a>12||a<0||b>59||b<=0)

printf("time error!");

c=5.5*b-30*a;

if(c<0) c=c*(-1);

printf("At %d:%d the angle is %.1f\n",a,b,c);

}