本帖最後由 鄭繼威 於 2023-3-31 19:13 編輯
將輸入的秒數, 換算成幾週, 幾天, 幾小時, 幾分鐘, 幾秒.
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- cout<<"請輸入想換算的秒數: ";
- int secs;
- cin>>secs;
- cout<<secs<<"秒可換算為..."<<endl;
- if(secs>=(60*60*24*7)){
- //換算周
- cout<<secs/(60*60*24*7)<<"週, ";
- secs=secs%(60*60*24*7);
- }
- if(secs>=(60*60*24)){
- //換算天
- cout<<secs/(60*60*24)<<"天, ";
- secs=secs%(60*60*24);
- }
- if(secs>=(60*60)){
- cout<<secs/(60*60)<<"小時, ";
- secs=secs%(60*60);
- }
- if(secs>=(60)){
- cout<<secs/(60)<<"分鐘,";
- secs=secs%(60);
- }
- if(secs>=(1)){
- cout<<secs/(1)<<"秒,";
- }
-
- cout<<endl;
-
- system("pause");
- return 0;
- }
複製代碼 |