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

[复制链接]
查看11 | 回复1 | 2010-5-4 12:53:06 | 显示全部楼层 |阅读模式
#include unsigned longseconds(int h,int m,int s){ unsigned longss=0; ss=s+60*m+60*60*h; return ss;}void main(void){ int h,m,s; unsigned longse; 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);}
回复

使用道具 举报

千问 | 2010-5-4 12:53:06 | 显示全部楼层
#include#include 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;}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行