c语言问题!!!!急!!!!高分悬赏!!!!

来源:百度知道 编辑:UC知道 时间:2024/06/09 02:24:16
数字式电子时钟
#include <stdio.h>
#include <conio.h>
void main()
{
int sec=0,min=0,hour=0,i;
while (1)
{
sleep(1);
sec++;
if (sec >= 60)
{
sec -= 60;
min++;
if (min >= 60)
{
min -= 60;
hour++;
if (hour >= 24)
{
hour -= 24;
}
}
}
printf("%d:%d:%d\r ", hour, min, sec);

}
getch();
}
要求:改成可以读取系统时间的程序,最好是在原代码基础上加代码,答案好的还有追加分数

#include <dos.h>
#include <stdio.h>

void main(void)
{
struct time curtime,newtime;

while(1)
{
if (kbhit())
break;
gettime(&newtime);
if (newtime.ti_sec!=curtime.ti_sec) /*一秒钟更新一次*/
printf("%2d:%2d:%2d\n",newtime.ti_hour,newtime.ti_min,newtime.ti_sec);
curtime=newtime;
}

getch();
printf("Program End\nPress any key to exit:");
getch();
}

/*********以下是修改你的程序***********/
#include <dos.h>
#include <stdio.h>
void main()
{
int sec=0,min=0,hour=0,i;

struct time newtime;
gettime(&newtime);
hour=newtime.ti_hour;
min =newtime.ti_min;
sec =newtime.ti_sec;

while (1)
{
sleep(1);
sec++;
if (sec >= 60)
{
sec -= 60;
min++;
if (min &