编写程序把秒转换为时分秒的形式

编写下列函数:

void split_ time (long int total_ sec, int *hr, int *min,int *sec) ;

total_ sec是以从午夜计算的秒数表示的时间。hr. mi n和sec都是指向变量的指针,这些变量在函数中将分别存储着按小时算(0~23) 、按分钟算(0~59) 和按秒算(0~59) 的等价的时间。

程序如下:

#include <stdio.h>

void split_time(long int total_sec, int *hr, int *min, int *sec);

main(){
    long int total_sec;
    int h, m, s;
    printf("Enter total seconds:");
    scanf("%ld", &total_sec);
    
    split_time(total_sec, &h, &m, &s);
    printf("Converted time: %2d:%2d:%2d", h, m, s);
    return 0;    
}

void split_time(long int total_sec, int *hr, int *min, int *sec){
    *hr = total_sec / 3600;
    *min = total_sec % 3600 / 60;
    *sec = total_sec % 3600 % 60;    
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值