# C语言钟表【改进版】

改进版源代码：

#include<stdio.h>
#include<graphics.h>
#include<math.h>
#include<dos.h>
#define PI 3.1415926
#define x 320
#define y 240
int main()
{
int gdriver = DETECT,gmode,i,l;
float th_hour,th_min,th_sec,m,n,x1,y1,x2,y2;
struct time curtime;
initgraph(&gdriver,&gmode,"");
while(! kbhit())
{
for(i=0;i<60;i++)
{
if(i%5==0)
{
l=15 ;
setcolor(13);
}

else
{
l=5;
}
x1=200*cos(i*6*PI/180)+320;
y1=200*sin(i*6*PI/180)+240;
x2=(200-l)*cos(i*6*PI/180)+320;
y2=(200-l)*sin(i*6*PI/180)+240;
line(x1,y1,x2,y2);
if(i%5==0)
{
switch(i)
{
case 0 :
outtextxy(x2-9,y2-2,"3");
break;
case 5 :
outtextxy(x2-10,y2-6,"4");
break;
case 10 :
outtextxy(x2-7,y2-9,"5");
break;
case 15 :
outtextxy(x2-2,y2-10,"6");
break;
case 20 :
outtextxy(x2-1,y2-10,"7");
break;
case 25 :
outtextxy(x2+3,y2-7,"8");
break;
case 30 :
outtextxy(x2+4,y2-2,"9");
break;
case 35 :
outtextxy(x2+2,y2+1,"10");
break;
case 40 :
outtextxy(x2+1,y2+3,"11");
break;
case 45 :
outtextxy(x2-7,y2+4,"12");
break;
case 50 :
outtextxy(x2-5,y2+3,"1");
break;
case 55 :
outtextxy(x2-9,y2,"2");
break;
}
}
setcolor(9);
}
gettime(&curtime);

/*得到当前系统时间*/
gotoxy(40,18);      /*定位输出位置*/
setcolor(7);
outtextxy(getmaxx()/2-30,getmaxy()/4,"UESTC_TerryLi");
setcolor(2);
rectangle(0,0,getmaxx(),getmaxy());
rectangle(20,20,getmaxx()-20,getmaxy()-20);
line(0,0,20,20);
line(getmaxx(),0,getmaxx()-20,20);
line(0,getmaxy(),20,getmaxy()-20);
line(getmaxx(),getmaxy(),getmaxx()-20,getmaxy()-20);
printf("Now Time:");
printf("%.0f:",(float)curtime.ti_hour);
if((float)curtime.ti_min<10) printf("0");
printf("%.0f:",(float)curtime.ti_min);
if((float)curtime.ti_sec<10) printf("0");
printf("%.0f",(float)curtime.ti_sec);
/*获得三个
圆*/
setcolor(11);
circle(x,y,200);
circle(x,y,12);
setcolor(4);         /*the first  */
circle(x,y,3);       /*the second */
setfillstyle(1,4);   /*the third  */
floodfill(x,y,4);    /*fouth      */ /*si bu chan sheng zhong jian de hong yuan xin*/
th_sec=(float)curtime.ti_sec*0.1047197551;                 /*2π/60=0.1047197551*/
th_min=(float)curtime.ti_min*0.1047197551+th_sec/60.0;
th_hour=(float)curtime.ti_hour*0.523598775+th_min/12.0;    /*2π/12=0.5235987755 */
/*draw hour point*/
m = x + 90*sin(th_hour);     /*70*/
n = y - 90*cos(th_hour);
setcolor(13);
line(x,y,m,n);
/*draw minute point*/        /*110*/
m = x + 130*sin(th_min);
n = y - 130*cos(th_min);
setcolor(11);
line(x,y,m,n);
/*draw second point*/         /*140*/
m = x + 170*sin(th_sec);
n = y - 170*cos(th_sec);
setcolor(5);
line(x,y,m,n);
sleep(1);
cleardevice();
}
closegraph();
return 0;
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：C语言钟表【改进版】 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)