题目:已知时、分、秒,以hh:mm:ss形式输出。
例如:时、分、秒分别为5、6、25
输出为:05:06:25
源程序:
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<stdlib.h>
void handel(char a[], int n)
{
int i=0;
for (;n>0;)
{
a[i++,i] = n % 60;
n = n/60;
}
}
int main()
{
int h, m, s, n, t, j;
char a[10]={0};
h=5,m=6,s=25;
t = s + m*60 + h*3600;
handel(a,t);
n=0;
for(j=3; j>=1; j--)
{
if(a[j]<10)
{
printf("0");//如果是<10的数则前面添0
}
printf("%d",a[j]); //输出时间
if (n++ < 2)
{
printf(":"); //输出分隔
}
}
return 0;
}
Dev-C++运行结果: