在本教程中,我们将讨论将秒转换为天,小时,分钟和秒的程序。
为此,我们将获得随机的秒数。我们的任务是将其分别转换为适当的天数,小时数,分钟数和秒数。
#include <bits/stdc++.h> using namespace std; //转换成正确的格式 void convert_decimal(int n) { int day = n / (24 * 3600); n = n % (24 * 3600); int hour = n / 3600; n %= 3600; int minutes = n / 60 ; n %= 60; int seconds = n; cout << day << " " << "days " << hour << " " << "hours " << minutes << " " << "minutes " << seconds << " " << "seconds " << endl; } int main(){ int n = 126700; convert_decimal(n); return 0; }
输出结果
1 days 11 hours 11 minutes 40 seconds