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/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

发表回复

登录后才能评论