- #include<iostream>
- #include<cstdlib>
- #include<ctime>
- using namespace std;
- int main(){
- float sec,start,end=0;
- cout<<"請輸入你要倒數的秒數:";
- cin>>sec;
- start=clock();
- while(end<sec*1000){
- end=clock()-start; //經過的秒數
- cout<<"倒數:"<<sec-((end)/1000) <<"秒!";
- // cout<<"正數:"<<(end)/1000<<"秒!";
- system("cls");
- }
- cout<<"時間到!共經過了"<<end<<"毫秒!"<<endl;
- system("pause");
- return 0;
- }
複製代碼 |