本帖最後由 許婷芳 於 2019-11-22 21:06 編輯
將輸入的秒數, 換算成幾週, 幾天, 幾小時, 幾分鐘, 幾秒.
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int t;
- cout<<"請輸入要換算的秒數: ";
- cin>>t;
- cout<<t<<"秒可換算為..."<<endl;
- cout<<t/(7*24*60*60)<<"週, ";
- t%=(7*24*60*60);
- cout<<t/(24*60*60)<<"天, ";
- t%=(24*60*60);
- cout<<t/(60*60)<<"小時, ";
- t%=(60*60);
- cout<<t/60<<"分鐘, ";
- t%=60;
- cout<<t<<"秒."<<endl;
- system("pause");
- return 0;
- }
複製代碼 |