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