1. 程式人生 > >用結構體的方法[ 定義時間結構體,輸入某一時刻的時間,輸出下一秒的時間]

用結構體的方法[ 定義時間結構體,輸入某一時刻的時間,輸出下一秒的時間]

#include<stdio.h>
int main() {
struct Time {
    int h;
    int m;
    int s;
        }t1,t2;
scanf("%d:%d:%d",&t1.h,&t1.m,&t1.s);
t2.s=t1.s+1;
t2.m=t1.m;
t2.h=t1.h;
if(t2.s==60){
        t2.m=t1.m+1;
        t2.s=0;
}
if(t2.m==60)
    {
        t2.h=t1.h+1;
        t2.m=0;
}
if(t2.h==24
){ t2.h=0; } printf("%d:%d:%d",t2.h,t2.m,t2.s); return 0; }