1、實現動態顯示當前計算機時間
#include
#include
int main()
{
int h = 0;
int m = 0;
int s = 0;
int t = 0;//存儲time函數的返回值
while(1){
t = time(0);//取得當前的時間(秒的總和)
//將t拆分為時分秒
s = t%60;
m = t%3600/60;
h = (t%(24*3600)/3600 + 8)%24;//東8區
printf("%02d:%02d:%02d\r", h, m, s);
fflush(stdout);
while(t == time(0));//等待這一秒過去
}
return 0;
}
2、猜數字游戲
#include
#include
#include
int main()
{
int data = 0;
int count = 0;
srand(time(0));
data = rand()%100;
printf("猜數游戲:(0~100)\n");
while(1){
int t = 0;
printf("請輸入猜想數:");
count++;
scanf("%d", &t);
if(t>data){
printf("太大了\n");
}else if(t