返回列表 發帖

時間換算機 (二)

將輸入的秒數, 換算成幾週, 幾天, 幾小時, 幾分鐘, 幾秒.



本帖隱藏的內容需要回復才可以瀏覽

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<iomanip>
  4. using namespace std;
  5. int main()
  6. {
  7.     int a;
  8.     cout<<"請輸入您想換算的秒數: ";
  9.     cin>>a;
  10.     cout<<a<<"秒可換算為..."<<endl;
  11.         cout<<a/604800<<"週, ";
  12.         a=a%604800;
  13.         cout<<a/86400<<"天, ";
  14.         a=a%86400;
  15.         cout<<a/3600<<"小時, ";
  16.         a=a%3600;
  17.         cout<<a/60<<"分鐘, ";
  18.         a=a%60;
  19.         cout<<a<<"秒."<<endl;
  20.         system("pause");
  21.         return 0;
  22. }
複製代碼

TOP

本帖最後由 陳育霖 於 2023-12-23 13:41 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<iomanip>
  4. using namespace std;
  5. int main()
  6. {
  7.     int a;
  8.     cout<<"請輸入您想換算的秒數: ";
  9.     cin>>a;
  10.     cout<<a<<"秒可換算為..."<<endl;
  11.         cout<<a/604800<<"週, ";
  12.         a=a%604800;
  13.         cout<<a/86400<<"天, ";
  14.         a=a%86400;
  15.         cout<<a/3600<<"小時, ";
  16.         a=a%3600;
  17.         cout<<a/60<<"分鐘, ";
  18.         a=a%60;
  19.         cout<<a<<"秒."<<endl;
  20.         system("pause");
  21.         return 0;
  22. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<iomanip>
  4. using namespace std;
  5. int main()
  6. {
  7.     int a;
  8.     cout << "請輸入您想換算的秒數: ";
  9.     cin >> a;
  10.     cout << a << "秒可換算為..." << endl;
  11.     if(a/604800>1)
  12.     cout << a / 604800 << "週, ";
  13.     a = a % 604800;
  14.     if (a / 86400 > 1)
  15.     cout << a / 86400 << "天, ";
  16.     a = a % 86400;
  17.     if (a / 3600 > 1)
  18.     cout << a / 3600 << "小時, ";
  19.     a = a % 3600;
  20.     if (a / 60 > 1)
  21.     cout << a / 60 << "分鐘, ";
  22.     a = a % 60;
  23.     if (a > 0)
  24.     cout << a << "秒." << endl;
  25.     system("pause");
  26.     return 0;
  27. }
複製代碼

TOP

  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int s;
  6.     cout << "請輸入換算的秒數: ";
  7.     cin >> s;
  8.     cout << s << "秒可換算為..." << endl;
  9.     if (s/604800){
  10.         cout << s/604800 << "週" << " ";
  11.         s = s%604800;
  12.     }
  13.     if (s/86400){
  14.         cout << s/86400 << "天" << " ";
  15.         s = s%86400;
  16.     }
  17.     if (s/3600){
  18.         cout << s/3600 << "小時" << " ";
  19.         s = s%3600;
  20.     }
  21.     if (s/60){
  22.         cout << s/60 << "分鐘" << " ";
  23.         s = s%60;
  24.     }
  25.     if (s){
  26.         cout << s << "秒" << endl;
  27.     }
  28.     return 0;
  29. }
複製代碼

TOP

返回列表