在C ++中将秒转换为天,小时,分钟和秒
在本教程中,我们将讨论将秒转换为天,小时,分钟和秒的程序。
为此,我们将获得随机的秒数。我们的任务是将其分别转换为适当的天数,小时数,分钟数和秒数。
示例
#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
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短