本帖最後由 陳品肇 於 2019-7-20 10:17 編輯
將輸入的秒數, 換算成幾週, 幾天, 幾小時, 幾分鐘, 幾秒.- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int time;
- cout<<"請輸入您想換算的秒數: ";
- cin>>time;
- cout<<time<<"秒可換算為...."<<endl;
- //1週秒數 1*7*24*60*60 = 604800 秒
- // 1天 86400 秒 ;1hr = 3600s ;1min = 60s
-
- cout<<time/604800<<"週, ";
- time = time%604800;
-
- cout<<time/86400<<"天, ";
- time = time%86400;
-
- cout<<time/3600<<"小時, ";
- time = time%3600;
- cout<<time/60<<"分鐘, "<<time%60<<"秒."<<endl;
-
- system("pause");
- return 0;
- }
複製代碼 |