4编写一个程序,要求用户以整数方式输入秒数(使用long变量存储),然后以天、小时、分钟和秒的方式显示这段时间。使用符号常量来表示每天有多少小时 每小时有多少分钟以及每分钟有多少秒。该程序的输出应与下面类似: Enter the number ofseconds:31600000 31600000 seconds=365 days46 minutes,40 seconds
时间: 2023-05-26 18:06:29 浏览: 114
```
#include <stdio.h>
#define HOURS_PER_DAY 24
#define MINUTES_PER_HOUR 60
#define SECONDS_PER_MINUTE 60
int main()
{
long seconds, days, hours, minutes;
printf("Enter the number of seconds: ");
scanf("%ld", &seconds);
days = seconds / (SECONDS_PER_MINUTE * MINUTES_PER_HOUR * HOURS_PER_DAY);
seconds %= SECONDS_PER_MINUTE * MINUTES_PER_HOUR * HOURS_PER_DAY;
hours = seconds / (SECONDS_PER_MINUTE * MINUTES_PER_HOUR);
seconds %= SECONDS_PER_MINUTE * MINUTES_PER_HOUR;
minutes = seconds / SECONDS_PER_MINUTE;
seconds %= SECONDS_PER_MINUTE;
printf("%ld seconds = %ld days %ld hours %ld minutes %ld seconds\n",
seconds, days, hours, minutes, seconds);
return 0;
}
```
阅读全文