Chương trình chuyển số giây thành ngày, giờ, phút, giây.
Cho số giây ngẫu nhiên, chuyển thành định dạng ngày/giờ/phút/giây.
Ví dụ
#include <bits/stdc++.h>
using namespace std;
void convert_decimal(int n) {
int day = n / (24 * 3600);
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;
}
Kết quả
1 days 11 hours 11 minutes 40 seconds