c語言鐘錶編寫,C語言編寫時鐘

本文目錄一覽:

C語言 用Devc++編一個圖形時鐘,要求能在devc++上運行的,簡簡單單的就可以了。

//圖形庫是EGE,下載後配置一下

#include iostream

#include “graphics.h”

#include math.h

#include time.h

#include windows.h

#define x0 210.0

#define y0 210.0

#define r 200.0

POINT pt[60],pt_s[60],pt_m[60],pt_h[60],pt1[60];

using namespace std;

int main()

{

initgraph(420,420);

setfillcolor(0xffccff);

setcolor(0xffccff);

fillellipse(x0,y0,10,10);

int s=45,m,h,n=0;

while(n60)

{

pt_s[s].x=x0+(int)((r-20)*cos((n-90)*3.1415926/30.0));

pt_s[s].y=y0+(int)((r-20)*sin((n-90)*3.1415926/30.0));

pt_m[s].x=x0+(int)((r-50)*cos((n-90)*3.1415926/30.0));

pt_m[s].y=y0+(int)((r-50)*sin((n-90)*3.1415926/30.0));

pt_h[s].x=x0+(int)((r-80)*cos((n-90)*3.1415926/30.0));

pt_h[s].y=y0+(int)((r-80)*sin((n-90)*3.1415926/30.0));

pt[s].x=x0+(int)(r*cos((n-90)*3.1415926/30.0));

pt[s].y=y0+(int)(r*sin((n-90)*3.1415926/30.0));

fillellipse(pt[s].x,pt[s].y,2,2);

n++;

s++;

if(s=60)

{

s=0;

}

}

for(int i=0;i12;i++)

{

fillellipse(pt[i*5].x,pt[i*5].y,5,5);

}

int xs,ys,xm=-1,ym=-1,xh=-1,yh=-1;

while(1)

{

int n,m;

SYSTEMTIME st={0};

GetLocalTime(st);

setcolor(0xffccff);

line(x0,y0,pt_s[st.wSecond].x,pt_s[st.wSecond].y);

xs=pt_s[st.wSecond].x;

ys=pt_s[st.wSecond].y;

if(pt_m[st.wMinute].x!=xm  pt_m[st.wMinute].y!=ym)

{

setcolor(0);

line(x0,y0,xm,ym);

xm=pt_m[st.wMinute].x;

ym=pt_m[st.wMinute].y;

setcolor(0xffccff);

}

line(x0,y0,pt_m[st.wMinute].x,pt_m[st.wMinute].y);

if(st.wHour12)

{

n=st.wHour-12;

}

else

{

n=st.wHour;

}

m=(n*60+st.wMinute)/12;

line(x0,y0,pt_h[m].x,pt_h[m].y);

Sleep(1000);

setcolor(0x0);

line(x0,y0,xs,ys);

fillellipse(x0,y0,10,10);

}

closegraph();

return 0;

}

用”C語言”編寫一個指針型時鐘模擬的程序

#include”graphics.h”

#define PI 3.1416

#include”math.h”

#include”dos.h”

main()

{

int x0=320,y0=240,r0=150;

void init_sceen();

void sec();

init_sceen(x0,y0,r0);

sec();

closegraph();

}

void init_sceen(int x0,int y0,int r0)/********************************************/

{

int i,x,y,graphdriver,graphmode;

char s[10];

float alpha,a0=90;

graphdriver=DETECT;

initgraph(graphdriver,graphmode,””);

setbkcolor(3);

setcolor(2);

circle(x0,y0,r0);

circle(x0,y0,r0+30);

setfillstyle(SOLID_FILL,10);

floodfill(x0-r0-10,y0,2);

/*please input the time*/

for(i=12;i=1;i–)

{

alpha=(a0+30*(11-i)*PI/180);

x=x0+cos(alpha)*r0-16;

y=y0-sin(alpha)*r0;

sprintf(s,”%2d”,i);

setcolor(4);

settextstyle(0,0,2);

outtextxy(x,y,s);

}

/*input second*/

for(i=60;i=1;i–)

{

alpha=(a0+6*(60-i)*PI/180);

x=x0+cos(alpha)*(r0-20);

y=y0-sin(alpha)*(r0-20);

setcolor(14);

if(i%5==0)

circle(x,y,5);

else circle(x,y,2);

floodfill(x,y,14);

}

setlinestyle(0,0,3);

}

void sec(void) /******************************************************************/

{

int x,y,i,j,k,xj,yj,xk,yk,xi,yi,x0=320,y0=240,r0=150;

union REGS r;

unsigned char *shijie=””;

unsigned char *daa=””;

struct time tim;

struct date dat;

float alphai,alphak,alphaj,a0=90;

xi=x0;yi=y0;xj=x0;yj=y0;xk=x0;yk=y0;

do

{

/*intput the time*/

x=38;y=12;

gettime(tim);

sprintf(shijie,”%02d:%02d:%02d”,tim.ti_hour,tim.ti_min,tim.ti_sec);

setfillstyle(SOLID_FILL,0);

bar(245,190,375,210);

setcolor(15);

outtextxy(245,190,shijie);

/*input the date*/ /*****************************************************/

getdate(dat);

sprintf(daa,”%02d–%02d–%02d”,dat.da_year,dat.da_mon,dat.da_day);

/*setfillstyle(SOLID_FILL,3);*/

bar(225,290,395,310);

setcolor(RED);

outtextxy(225,290,daa);

x=190;y=430;

setcolor(RED);

outtextxy(x-26,y,”Designed by GuoLiuTa0″);

setcolor(LIGHTRED);

outtextxy(x+76,y0+20,”NBA GAME”);

setlinestyle(0,0,3);

k=tim.ti_hour;

j=tim.ti_min;

i=tim.ti_sec;

alphak=(a0+30*(12-k)-j*5/60.*6)*PI/180;

alphaj=(a0-6*j)*PI/180;

/*write second hand*/

alphai=(a0+6*(60-i))*PI/180;

x=x0+cos(alphai)*(r0-32);

y=y0-sin(alphai)*(r0-32);

setcolor(BLACK);

line(x0,y0,xi,yi);

setcolor(YELLOW);

line(x0,y0,x,y);

xi=x;

yi=y;

/*write minute hand*/

x=x0+cos(alphaj)*(r0-60);

y=y0-sin(alphaj)*(r0-60);

setcolor(BLACK);

line(x0,y0,xj,yj);

setcolor(BLUE);

line(x0,y0,x,y);

xj=x;

yj=y;

/*write hour hand*/

x=x0+cos(alphak)*(r0-99);

y=y0-sin(alphak)*(r0-99);

setcolor(BLACK);

line(x0,y0,xk,yk);

setcolor(RED);

line(x0,y0,x,y);

xk=x;

yk=y;

delay(10000);

}

while(!kbhit());

}

linux下怎樣用c語言編寫一個時鐘

我希望你只是需要如何知道時間,而不是寫你一個時鐘程序,那個太複雜了,如果只是想如何知道時間-

#include stdio.h

#include time.h

int main(void)

{

struct tm *tm_ptr;

time_t the_time;

(void)time(the_time);

tm_ptr=localtime(the_time);

printf(“Date: %04d/%02d/%02d\n”,

1900+tm_ptr-tm_year,tm_ptr-tm_mon+1,tm_ptr-tm_mday);

printf(“Time: %02d:%02d:%02d\n”,

tm_ptr-tm_hour,tm_ptr-tm_min,tm_ptr-tm_sec);

return(0);

}

原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/246208.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
小藍的頭像小藍
上一篇 2024-12-12 13:13
下一篇 2024-12-12 13:13

相關推薦

  • AES加密解密算法的C語言實現

    AES(Advanced Encryption Standard)是一種對稱加密算法,可用於對數據進行加密和解密。在本篇文章中,我們將介紹C語言中如何實現AES算法,並對實現過程進…

    編程 2025-04-29
  • 學習Python對學習C語言有幫助嗎?

    Python和C語言是兩種非常受歡迎的編程語言,在程序開發中都扮演着非常重要的角色。那麼,學習Python對學習C語言有幫助嗎?答案是肯定的。在本文中,我們將從多個角度探討Pyth…

    編程 2025-04-29
  • Python被稱為膠水語言

    Python作為一種跨平台的解釋性高級語言,最大的特點是被稱為”膠水語言”。 一、簡單易學 Python的語法簡單易學,更加人性化,這使得它成為了初學者的入…

    編程 2025-04-29
  • OpenJudge答案1.6的C語言實現

    本文將從多個方面詳細闡述OpenJudge答案1.6在C語言中的實現方法,幫助初學者更好地學習和理解。 一、需求概述 OpenJudge答案1.6的要求是,輸入兩個整數a和b,輸出…

    編程 2025-04-29
  • Python按位運算符和C語言

    本文將從多個方面詳細闡述Python按位運算符和C語言的相關內容,並給出相應的代碼示例。 一、概述 Python是一種動態的、面向對象的編程語言,其按位運算符是用於按位操作的運算符…

    編程 2025-04-29
  • Python語言由荷蘭人為中心的全能編程開發工程師

    Python語言是一種高級語言,很多編程開發工程師都喜歡使用Python語言進行開發。Python語言的創始人是荷蘭人Guido van Rossum,他在1989年聖誕節期間開始…

    編程 2025-04-28
  • Python語言設計基礎第2版PDF

    Python語言設計基礎第2版PDF是一本介紹Python編程語言的經典教材。本篇文章將從多個方面對該教材進行詳細的闡述和介紹。 一、基礎知識 本教材中介紹了Python編程語言的…

    編程 2025-04-28
  • Python語言實現人名最多數統計

    本文將從幾個方面詳細介紹Python語言實現人名最多數統計的方法和應用。 一、Python實現人名最多數統計的基礎 1、首先,我們需要了解Python語言的一些基礎知識,如列表、字…

    編程 2025-04-28
  • Python作為中心語言,在編程中取代C語言的優勢和挑戰

    Python一直以其簡單易懂的語法和高效的編碼環境而著名。然而,它最近的發展趨勢表明Python的使用範圍已經從腳本語言擴展到了從Web應用到機器學習等廣泛的開發領域。與此同時,C…

    編程 2025-04-28
  • Python基礎語言

    Python作為一種高級編程語言擁有簡潔優雅的語法。在本文中,我們將從多個方面探究Python基礎語言的特點以及使用技巧。 一、數據類型 Python基礎數據類型包括整數、浮點數、…

    編程 2025-04-28

發表回復

登錄後才能評論