##代码实现 ”秒表计时器“。运行过程中输入任意键退出
输入数字1开始计时,任意键结束计时
#define _CRT_SECURE_NO_WARNINGS 1 #include#include #include #pragma warning(disable:4996) //解决kbhit()的编辑错误 void gotoxy(int x, int y) //光标移动到(x,y)位置 { HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); COORD pos; pos.X = x; pos.Y = y; SetConsoleCursorPosition(handle, pos); } int main() { char a = 0; char input = 0; printf("技术宅拯救世界!!nnn"); input = getch(); if (input == '1') { printf("拯救开始计时:"); while (1) { if (kbhit())//判断是否再次输入 { printf("n拯救结束!在你的拯救下,世界暂时进入了和平状态nnn"); return 0; } a = a++; gotoxy(0,4); printf("%dn", a); Sleep(1000); } } return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)