本帖最後由 stephen 於 2010-2-20 23:26 編輯
C++第一題:將輸入之秒數轉換成「時:分:秒」。如輸入 10000,則輸出 02:46:40。- #include <iostream>
- using namespace std;
- int main(void){
- /*1.將輸入之秒數轉換成「時:分:秒」。如輸入 10000,則輸出 02:46:40。 */
-
- int time;
- cout << "Please input second to transfer : " << endl;
- cin >> time;
-
- cout << time / 3600 << " : "; // get hours
- time = time - ((time / 3600) * 3600); // get second cut hours
- cout << time / 60 << " : "; // get Minutes
- time = time - ((time / 60) * 60); // get second cut Minutes
- cout << time << endl; // seconds
-
- system("pause");
- return 0;
- }
複製代碼 |