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