當前位置:首頁 » 編程語言 » 倒計時c語言代碼天數
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

倒計時c語言代碼天數

發布時間: 2022-07-23 21:12:53

Ⅰ 倒計時器代碼

程序設計思想:
(1)輸入目標時間,高考的年,月,日,時,分,秒
下面例子中簡寫成直接賦值。
(2)轉換成 struct tm
(3)再轉換成 time_t
(4) 獲當前時間 now = time (NULL);
(5)用difftime 計算時間差,送返 long double 秒
(6)把秒轉換成 日,時,分,秒
(7)循環 (下面例子中簡寫成 列印120次,每隔2秒左右打一次)

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void wait ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLK_TCK ;
while (clock() < endwait) {}
}

void main(){
time_t rawtime;
struct tm * target_time;
int d,h,m,s;
int k=0;
long double dif,r;
time_t now,t_end; // in sec

/* get current timeinfo and modify it to the user's choice */
time ( &rawtime );
target_time = localtime ( &rawtime );

// time struc and to time_t
target_time->tm_year = 2008 - 1900; //year - 1900
target_time->tm_mon= 7 - 1; // month - 1
target_time->tm_mday = 15 ; // day
target_time->tm_hour = 13 ; // hour
target_time->tm_min = 1 ;
target_time->tm_sec = 1 ;
t_end = mktime (target_time);
// printf("%s ",ctime(&t_end)); //print and check

while (k < 120)
{
now = time (NULL);
// printf("%s ",ctime(&now)); // print and check
dif = difftime (t_end,now); //double , time_t time_t
// printf( "%lf\n",dif);
d = (int) (dif / 86400.0);
r = dif - d * 86400.0;
h = (int) (r / 3600.0);
r = r - h * 3600.0;
m = (int) (r / 60.0);
r = r - m * 60.0;
s = (int) (r);
printf("%d--days %d--hours %d--min %d--sec\n",d,h,m,s);
(void) wait ( 2 ); // every 2 seconds print
k = k + 1;

};
}

c語言問題,關於日期倒計時(附說明,謝謝)

你好!是什麼編程環境呢

Ⅲ c語言 倒計時程序

對硬體的啊。

P2=0;
P1=display_code[display_data[i]];
P2=k;
k=k>>1;
不懂。

不過感覺問題不大。先把main里的i的上限從250改到216.
在display()里做3個判斷(可能會要做個全局變數,或者加個參數,記錄當前是多少。)
判斷是否是0,大於10,大於100
另外,站長團上有產品團購,便宜有保證

Ⅳ 如何在c語言程序中插入一個倒計時命令

#include <stdio.h>
int main()
{
printf("hello world");
for(int i=60;i>0;i--)
{
printf("%d",i);
Sleep(1000);
}
}

Ⅳ c語言 製作 倒計時

#include"stdio.h"

#include"Windows.h"

intmain(){

printf("請輸入倒計時時間(例如:01:26:30):");

inthour=0,min=0,sec=0;

scanf("%d:%d:%d",&hour,&min,&sec);

if(hour>24||hour<0||min>60||min<0||sec>60||sec<0){

printf("輸入有誤! ");

return0;

}

printf("倒計時開始! ");

inti,j,k;

for(i=hour;i>=0;i--){

for(j=min;j>=0;j--){

for(k=sec;k>=0;k--){

printf(" %2d:%2d:%2d",i,j,k);

Sleep(1000);

}

sec=59;

}

min=59;

}

exit(0);

}

Ⅵ 用c語言設定一個紀念日時間,輸入一個日期,顯示當天距離紀念日的天數。

#include "stdio.h"
#include "Windows.h"
int main() {
printf("請輸入倒計時時間(例如:01:26:30):");
int hour=0, min=0, sec=0;
scanf("%d:%d:%d", &hour, &min, &sec);
if(hour>24 || hour<0 || min>60 || min<0 || sec>60 || sec<0) {
printf("輸入有誤!\n");
return 0;
}
printf("倒計時開始!\n");
int i, j, k;
for(i=hour; i>=0; i--) {
for(j=min; j>=0; j--) {
for(k=sec; k>=0; k--) {
printf("\r%2d:%2d:%2d", i, j, k);
Sleep(1000);
}
sec = 59;
}
min = 59;
}
exit(0);
}

Ⅶ c語言 倒計時時鍾程序

如果你有TC,可以試一試。
VC 的 kbhit() 不能返回 鍵名。
23:59:59 -- 86400 秒

#include <stdio.h>
#include <windows.h>
#include <conio.h>

void main()
{
long int t;
int flag =0;
t = 86400;

printf("press S start, press E stop\n");
while(1)
{
if (kbhit() == 'S' || kbhit() == 's') flag =1;
if (kbhit() == 'E' || kbhit() == 'e') flag =0;
Sleep(1000);
if (flag == 1) t = t -1;
if (t <= 0) break;
printf("%d ",t);
}

Ⅷ 求個c語言小代碼,很簡單的倒計時程序


#include<stdio.h>
#include<windows.h>

intmain(void)
{
inta;
a=0;
boolup=true;
system("color0A");

while(true)
{
system("cls");

printf("%d a",a);
Sleep(100);
if(up)
{
a++;
}
if(!up)
{
a--;
}
if(a==0)
{
up=true;
}
if(a==100)
{
up=false;
}

}

return0;
}

Ⅸ c語言倒計時怎麼編

定位要倒計時的坐標!然後再需要倒計時的地方添加gotoxy(所定位的坐標),當然這只是十以下的倒計時,超過了十則會清除不了十位數上的數字,要解決這個辦法就是輸出%2d

Ⅹ c語言倒計時器 的編程代碼

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void wait ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLK_TCK ;
while (clock() < endwait) {}
}

void main(){
int t,m,s;
printf("input counterdown time in seconds\n");
scanf("%d",&t);
printf("\n===================\n");
while(1)
{
wait ( 1 );
t--;
if (t==0) break;
s = t % 60;
m = t / 60;
printf("\r\t%02d:%02d",m,s);
}
exit(0);
};