C语言编写简单时钟程序
1、首先打开VC++
2、文件》》新建
3、新建一个C++文档
4、先声明头文件#include <stdio.h> #include <math.h>#in艘早祓胂clude <dos.h>#include <conio.h>
5、声明变量struct time curtime;float th_hour,th_min,th_sec;
6、主要代码do{print酆璁冻嘌f("****************************************忮氽阝另*****\n");printf("** This is a simple clock program. **\n");printf("** **\n");printf("*********************************************\n");printf("The current time is:\n");gettime(&curtime); /*得到当前系统时间*/if((float)curtime.ti_hour<=12) /*午前的处理*/{printf("AM ");if((float)curtime.ti_hour<10) printf("0"); /*十点之前在小时数前加零*/printf("%.0f:",(float)curtime.ti_hour);}else /*午后的处理*/{printf("PM ");if((float)curtime.ti_hour-12<10) printf("0");printf("%.0f:",(float)curtime.ti_hour-12);}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);printf("\n");printf("\n");printf("\n");printf("\n");printf("\n");printf("\n");sleep(1); /*延时一秒后刷新*/clrscr();}while(1);
7、如果代码提示有错的,说明你的VC++没有导入dos库文件