1026. 程序运行时间(15)

本文介绍了一种将秒数转换为时分秒显示格式的方法,并提供了完整的C语言代码实现。通过输入两个时间点的秒数差值,程序能够准确地将其转换为易于阅读的时分秒格式。

原题: https://www.patest.cn/contests/pat-b-practise/1026

实现思路: 就是转换输入格式的问题, 给秒转成"时分秒"显示格式.

完整代码:

#include <stdio.h>

int main (void) {
    float CLK_TCK = 100.0;
    int c1;
    int c2;
    int source;
    int h = 0;
    int m = 0;
    int s = 0;

    scanf("%d %d", &c1, &c2);
    source = (int)((c2 - c1) / CLK_TCK + 0.5);
    h = source / 3600;
    m = (source - h * 3600) / 60;
    s = source - h * 3600 - m * 60;
    printf("%02d:%02d:%02d\n", h, m, s);

    return 0;
}

转载于:https://www.cnblogs.com/asheng2016/p/7823105.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值