在 C++ 中轉換秒為天、時、分和秒
在本教程中,我們將討論一個將秒轉換為天、時、分和秒的程式。
為此,我們將提供一個隨機秒數。我們的任務是將其分別轉換為適當的天數、小時數、分鐘數和秒數。
示例
#include <bits/stdc++.h>
using namespace std;
//converting into proper format
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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP