- #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*1000-end)/1000<<" 秒!";
- cout<<"正數:"<<(end)/1000<<" 秒!";
- system("cls");
- }
- cout<<"時間到!共經過了 "<<end/1000<<" 秒!"<<endl;
-
- system("pause");
- return 0;
- }
複製代碼 |