编写一个程序,要求用户以整数方式输入 秒数(使用long 或long long变量存储),然后以天、小时、分钟和秒的方式显示这段时间。使用符号常量来表示每天有多少小时、每小时有多少分钟以及每分钟有多少秒。该程序的输出应与下面类似:
Enter the number of seconds: 3160000 3160000 seconds = 365 days, 17 hours, 46 minutes, 40 seconds
#include<iostream>
using namespace std;
const int DaytoHour(24);
const int HourtoMinute(60);
const int MinutetoSecond(60);
int main()
{
long long second;
int D,H,M,S;
cout<<"Enter the number of seconds:";
cin>>second;
S=second;
M=S/MinutetoSecond;
H=M/HourtoMinute;
D=H/DaytoHour;
H=H%DaytoHour;
M=M%HourtoMinute;
S=S%MinutetoSecond;
cout<<second<<" seconds = "<<D<<" days, "<<H<<" hours, "<<M<<" minutes, "<<S<<" seconds";
return 0;
}