C语言秒的转换

Python019

C语言秒的转换,第1张

根据输入的秒数,转换成相应的时,分,秒数据输出过程为:定义变量h,m,s来存储转换结果定义seconds变量,接收用户输入得到小时数:h=seconds/3600去除小时数:seconds%=3600

得到分钟数:m=seconds/60得到秒数:s=seconds%60输出结果参考代码:#includeint

main(){

int

h,m,s,seconds

printf("input

sec:

")scanf("%d",

&seconds

)

h=seconds/3600

seconds

%=

3600

m=seconds/60

s=seconds%60

printf("%d:%d:%d\n",

h,m,s

)

return

0}运行结果:input

sec:

145674:2:47

#include <stdio.h>

int main()

{

    int t

    int h,m,s

    scanf("%d",&t)

    h = t/3600

    m=t/60%60

    s=t%60

    printf("%02d:%02d:%02d\n", h,m,s)

    

    return 0

}