c语言,编程题 输入一个以秒为单位的时间值,将其转换为“时:分:秒”的形式输出,将转换操作定义为函数
发布网友
发布时间:2022-04-30 14:15
我来回答
共3个回答
热心网友
时间:2023-10-05 11:11
#include <stdio.h>
main()
{
char s[24];
int sec;
scanf("%d", &sec);
s2hms(s,sec);
printf("%s\n",s);
}s2hms(char* str, int sec)
{
int h,m,s;
h = sec/3600;
m = sec/60 - 60* h;
s = sec - 3600* h - 60*m;
sprintf(str,"%d:%d:%d",h,m,s);
}
热心网友
时间:2023-10-05 11:12
#include<stdio.h>
void fun(int s){
printf("%d:%d:%d\n",s/3600%24,s/60%60,s%60);
}
main(){
int s;
scanf("%d",&s);
fun(s);
}
热心网友
时间:2023-10-05 11:12
#include <stdio.h>
void print(int ss){
int h,m,s;
s = ss%60;
ss /=60;
m = ss%60;
h = ss/60;
printf("%2d:%2d:%2d", h, m ,s);
}