定义一个结构体变量(包含时,分,秒)编写一个程序,输出当前时间的下一秒

c语言题

第1个回答  2014-01-05

#include <stdio.h>


struct  myTime

{

    int h;

    int m;

    int s;

};


int main()

{

    struct myTime T;

    int h,m,s;

    scanf("%d",&h);

    scanf("%d",&m);

    scanf("%d",&s);

    T.h=h;

    T.m=m;

    T.s=s;

    if (s==59)

    {

        T.s=0;

        T.m++;

        if (T.m==60)

        {

            T.m=0;

            T.h++;

            if (T.h==24)

            {

                T.h=0;

            }

        }

    } 

    else

    {

        T.s++;

    }

    printf("%2d:0%d:%2d\n",h,m,s,T.h,T.m,T.s);

    return 0;

}

相似回答