编写一个函数,用时间 时,分,秒作为函数的三个形参,函数返回至0点钟到指定时间的秒数。

编写一个函数,用时间 时,分,秒作为函数的三个形参,函数返回至0点钟到指定时间的秒数。并用这个函数计算同一天两个时间之间的秒数
最好详细点。万分感谢~

#include <stdio.h>
unsigned long seconds(int h,int m,int s)
{
unsigned long ss=0;
ss=s+60*m+60*60*h;
return ss;
}
void main(void)

{
int h,m,s;
unsigned long se;
scanf("%d%d%d",&h,&m,&s);//输入时间,最好加以判断,以防用户输入错误的时间分秒数.这里没有判断
se=seconds(h,m,s);//调用函数,返回秒值
printf("h:%d m:%d s:%d\n",h,m,s);
printf("%ld",se);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-05-04
#include<iostream>
#include <cmath>
using namespace std;
int second_caculate(int hour,int minute,int second,int hour_2,int minute_2,int second_2)
{
int t=(hour_2-hour)*3600+(minute_2-minute)*60 +second_2-second;
return abs(t);
}
int main()
{
cout<<second_caculate(2,30,30,1,30,30)<<endl;
return 1;
}
相似回答