간단 한 시간 시 뮬 레이 션 (C)

#include <stdio.h>
//   ,    
typedef struct student
{
    int second;
    int minute;
    int hour;
};
void Update(struct student *p);
void Display(struct student *p);
void Delay();
//   
int main()
{
    //long i;
    struct student a,*p;
    a.second=-1;
    a.minute=0;
    a.hour=0;
    p=&a;
    Update(p);
    return 0;
}
//    ,           
void Update(struct student *p)
{
    struct student a;
    while (p->second<61)
    {if (p->second>=59)
    {
        p->second=p->second-60;
        p->minute=p->minute+1;
    }
    if (p->minute>=59)
    {
       p->minute=p->minute-60;
        p->hour=p->hour+1;
    }
    if (p->hour>=23)
        p->hour=p->hour-24;
        p->second=p->second+1;
        Display(p);
        Delay();
    }
}
//    
void Display(struct student *p)
{
    printf ("%2d:%2d:%2d\r",p->hour,p->minute,p->second);
}
//      ,  300000000      
void Delay()
{
    long h=0;
    while (h!=300000000)
    {h++;
    }
}

좋은 웹페이지 즐겨찾기