c语言函数写一个时钟,c语言关于时间的函数-成都快上网建站

c语言函数写一个时钟,c语言关于时间的函数

用C语言 编写 一个时钟程序

#includegraphics.h

成都创新互联主要从事做网站、网站制作、网页设计、企业做网站、公司建网站等业务。立足成都服务迭部,10余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18982081108

#includemath.h

#includedos.h

#define pi 3.1415926

#define X(a,b,c) x=a*cos(b*c*pi/180-pi/2) 300;

#define Y(a,b,c) y=a*sin(b*c*pi/180-pi/2) 240;

#define d(a,b,c) X(a,b,c);Y(a,b,c);line(300,240,x,y)

void init()

{int i,l,x1,x2,y1,y2;

setbkcolor(1);

circle(300,240,200);

circle(300,240,205);

circle(300,240,5);

for(i=0;i60;i )

{if(i%5==0) l=15;

else l=5;

x1=200*cos(i*6*pi/180) 300;

y1=200*sin(i*6*pi/180) 240;

x2=(200-l)*cos(i*6*pi/180) 300;

y2=(200-l)*sin(i*6*pi/180) 240;

line(x1,y1,x2,y2);

}

}

main()

{

int x,y;

int gd=VGA,gm=2;

unsigned char h,m,s;

suct time t[1];

initgraph(gd,gm,"d:\\tc");

init();

setwritemode(1);

gettime(t);

h=t[0].ti_hour;

m=t[0].ti_min;

s=t[0].ti_sec;

setcolor(7);

d(150,h,30);

setcolor(14);

d(170,m,6);

setcolor(4);

d(190,s,6);

while(!kbhit())

{while(t[0].ti_sec==s)

gettime(t);

sound(400);

delay(70);

sound(200);

delay(30);

nosound();

setcolor(4);

d(190,s,6);

s=t[0].ti_sec;

d(190,s,6);

if (t[0].ti_min!=m)

{

setcolor(14);

d(170,m,6);

m=t[0].ti_min;

d(170,m,6);

}

if (t[0].ti_hour!=h)

{ setcolor(7);

d(150,h,30);

h=t[0].ti_hour;

d(150,h,30);

sound(1000);

delay(240);

nosound();

delay(140);

sound(2000);

delay(240);

nosound();

}

}

getch();

closegraph();

}

怎样用C语言编写一个时钟,明天就要交了,急,求大神

#include stdio.h

#include time.h

int main()

{

int i=1;

for(i=0;i20;i++)

{

shijian();//显示时间

printf("%d秒后退出",20-i);

sleep(1000);//等待

// printf("输入数字0结束");

system("cls");//清屏

// scanf("%d",i);

}

system("pause");

}

int shijian()

{

time_t rawtime;

struct tm * timeinfo;

time ( rawtime );

timeinfo = localtime ( rawtime );

printf ( "\007当前时间: %s", asctime (timeinfo) );

}

c语言编时钟

这个行吗?

#include "stdio.h"

#include "time.h"

#include "dos.h"

#include "windows.h"

#include "string.h"

#include "ctype.h"

int year_r(); //显示年

int month_h(); //月

int date_e(); //日

int time_e(); //时间

char * time_ta(); //将日期时间转换成字符串

int wait_t(); //延时1秒

char * time_ta() //将日期时间转换成字符串

{

char *q;

time_t t;

t=time(NULL);

q=ctime(t);

//printf("*q_address = 0x%x\n",q);

return (q);

}

int wait_t() //延时1秒

{

long temp_total=0;

time_t time_temp;

time_temp=time(NULL);

temp_total=time_temp;

for(;;)

{

time_temp=time(NULL);

if(abs(time_temp - temp_total) =1)

break;

}

return (0);

}

int main()

{

int temp;

system("cls"); //清屏

printf("\n\n\n\n\n\n\n\n\t\t\t");

year_r();

printf("年");

temp = month_h();

if (temp != 13)

{

printf("%d",temp);

printf("月");

}

else printf("month error!\n");

date_e();

printf("日");

time_e();

printf("\r");

for(;;) //显示年月日时分秒

{

wait_t(); // 1秒钟到显示年月日时分秒

system("cls");

printf("\n\n\n\n\n\n\n\n\t\t\t");

year_r();

printf("年");

temp = month_h();

if (temp != 13)

{

printf("%d",temp);

printf("月");

}

else printf("month error!\n");

date_e();

printf("日");

time_e();

}

getchar();

}

int year_r() //显示年

{

char *p;

int i;

p=time_ta();

for(i=0;i24;i++,p++) //ctime函数返回字符为24个

if(i19i24)

printf("%c",*p);

return (0);

}

int month_h() //显示月

{

char month_n[12][5]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};

char *p;

char month[4]; //存放三个字符

int i,j=0;

p=time_ta();

for(i=0;i24;i++,p++) //i24因为ctime()函数返回有24个字符

{

if(i=4 i7) //取ctime函数返回值的第5--8共三个字符.

{

month[j++]=*p;

if(j==3)

{

month[j]='\0';

break;

}

}

}

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

{

if (strcmp(month_n[i],month) == 0)

{

return (i+1);

}

}

return (13);

}

int date_e() //日

{

int j=0,i=0;

char date[2];

char *p;

p=time_ta();

for(i=0;i24;i++,p++)

if(i=8i10)

{ date[j]=*p;

printf("%c",date[j++]);}

return 0;

}

int time_e() //时间

{ int i;

char *p;

p=time_ta();

for(i=0;i24;i++,p++)

if(i10i19)

printf("%c",*p);

printf("\n");

return (0);

}

c语言时钟代码

#includegraphics.h /* 引入graphic.h */

#includemath.h /* 引入math.h */

#includedos.h /* 引入dos.h */

#define pi 3.1415926 /*定义pi=3.14159*/

#define X(a,b,c) x=a*cos(b*c*pi/180-pi/2)+300;

#define Y(a,b,c) y=a*sin(b*c*pi/180-pi/2)+240;

#define d(a,b,c) X(a,b,c);Y(a,b,c);line(300,240,x,y) /*定义……*/

void init() /*初始化程序*/

{int i,l,x1,x2,y1,y2; /*定义……*/

setbkcolor(1); /*设置颜色*/

circle(300,240,200); /*作园*/

circle(300,240,205);

circle(300,240,5);

for(i=0;i60;i++) /*循环(算时间)*/

{if(i%5==0) l=15;

else l=5;

x1=200*cos(i*6*pi/180)+300;

y1=200*sin(i*6*pi/180)+240;

x2=(200-l)*cos(i*6*pi/180)+300;

y2=(200-l)*sin(i*6*pi/180)+240;

line(x1,y1,x2,y2);

}

}

main()

{

int x,y;

int gd=VGA,gm=2;

unsigned char h,m,s; /*定义*/

struct time t[1];

initgraph(gd,gm,"d:\\tc");

init();

setwritemode(1);

gettime(t);

h=t[0].ti_hour;

m=t[0].ti_min;

s=t[0].ti_sec; /*定义时分秒*/

setcolor(7); /*设置颜色*/

d(150,h,30);

setcolor(14);

d(170,m,6);

setcolor(4);

d(190,s,6);

while(!kbhit()) /*获取键盘相应*/

{while(t[0].ti_sec==s)

gettime(t); /*C语言中得到时间的函数*/

sound(400); /*计算时间……*/

delay(70);

sound(200);

delay(30);

nosound();

setcolor(4);

d(190,s,6);

s=t[0].ti_sec;

d(190,s,6);

if (t[0].ti_min!=m)

{

setcolor(14);

d(170,m,6);

m=t[0].ti_min;

d(170,m,6);

}

if (t[0].ti_hour!=h)

{ setcolor(7);

d(150,h,30);

h=t[0].ti_hour;

d(150,h,30);

sound(1000);

delay(240);

nosound();

delay(140);

sound(2000);

delay(240);

nosound();

}

}

getch(); /*设置空格后退出*/

closegraph();

}

具体的。。就是套用用几个函数算时间。。

不要对这种很长的东西害怕,其实大部分都是在画这个钟~

加油哦~


本文题目:c语言函数写一个时钟,c语言关于时间的函数
URL网址:http://kswjz.com/article/dssidcd.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流