c语言 时钟模拟
作者&投稿:凭秆 (若有异议请与网页底部的电邮联系)
#include "stdio.h"
#include "dos.h"
//#include
#include
#define S2M_M2H 60
struct N
{
int hour;
int minute;
int second;
} mytime = {0,0,0};
int main()
{
time_t rt;
struct tm *t;
time ( &rt );
t = localtime ( &rt );
mytime.hour=t->tm_hour;
mytime.minute = t->tm_min;
mytime.second = t->tm_sec;
//1楼答得不错,你不会自己合直来么,我帮你合起来了
//以后我白天不能上网,晚上来答一两个就玩去了,这题如果可行,就采纳1楼的,我没功劳
for(; ; mytime.second++)
{
if(mytime.second==S2M_M2H)
{
mytime.minute++;
mytime.second=0;
if(mytime.minute==S2M_M2H)
{
mytime.hour++;
mytime.minute=0;
}
}
{
printf("\b\b\b\b\b\b\b\b%2d:%02d:%02d",mytime.hour,mytime.minute,mytime.second);
delay(1000);
}
}
return 0;
}
表示的是回车(不换行)啊,\b才表示退格
#include<math.h>#include<dos.h>
#include<graphics.h>
#include<conio.h>
#include<time.h>
#define PI 3.141592653589793
int h,m,s,i,l,mon,y,d;
struct time t;
struct date data;
draw()
{
gettime(&t); //取得时间信息到t
s=t.ti_sec; //秒
h=t.ti_hour; //时
m=t.ti_min; //分
getdate(&data); //取得日期信息到data
y=data.da_year; //年
mon=data.da_mon; //月
d=data.da_day; //日
//画出钟的外圆(即是轮廓)
setcolor(11);
circle(300,200,152);
setcolor(3);
circle(300,200,157);
//画出60个分钟刻度
for(i=0;i<60;i+=1)
{
if(i%5==0) l=140;
else l=145;
line(300+150*sin(i*PI/30),200-150*cos(i*PI/30),
300+l*sin(i*PI/30),200-l*cos(i*PI/30));
}
//画秒针
setcolor(19);
line(300,200,300+140*sin(s*PI/30),200-140*cos(s*PI/30));
//画分针
setcolor(3);
line(300,200,300+110*sin(m*PI/30),200-110*cos(m*PI/30));
//画时针
setcolor(11);
line(300,200,300+90*sin(((float)h+(float)m/60)*PI/6),200-90*cos(((float)h+(float)m/60)*PI/6));
//标注钟盘上的"3"、"6"、"9"、"12"
settextstyle(3,0,2);
outtextxy(430,190,"3");
outtextxy(295,320,"6");
outtextxy(160,190,"9");
outtextxy(293,60,"12");
}
main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,""); //初始化屏幕模式
setbkcolor(8);
while(!kbhit()) //若有键盘输入则跳出(结束程序)
{
draw(); //绘制钟
settextstyle(3,0,5);
setcolor(9);
outtextxy(60,170,"my clock");
gotoxy(35,17);
//打印出数字形式的时间(hh:mm:ss)
if(h<10) printf("0");printf("%d:",h);
if(m<10) printf("0");printf("%d:",m);
if(s<10) printf("0");printf("%d",s);
gotoxy(33,18);
printf("%d:",y);
//打印出日期(mm:dd)
if(mon<10) printf("0");printf("%d:",mon);
if(d<10) printf("0");printf("%d",d);
sound(200); //让喇叭以200HZ叫一声
delay(70); //延时0.07秒,即是声音延续0.07秒
nosound(); //停止声音
sleep(1); //停止一秒
cleardevice(); //清屏
}
}
卓肃舒敏: #include<math.h> #include<dos.h> #include<graphics.h> #include<conio.h> #include<time.h> #define PI 3.141592653589793 int h,m,s,i,l,mon,y,d; struct time t; struct date data; draw() { gettime(&t); //取得时间信息到t s=t.ti_sec; //秒 h=t.ti_hour; ...
贵溪市13597414562: c语言模拟时钟的程序段 - ?
卓肃舒敏: #include<stdio.h>#include<windows.h>#include<conio.h> int main() { while(!kbhit()) { printf("时间是:"); system("time/t"); Sleep(1000); system("cls"); } }
贵溪市13597414562: 用C语言编辑一个模拟时钟. - ?
卓肃舒敏: ps:把#include<graphics.h> 换为#include <windows.h>,因为#include<graphics.h> 是TC的图形库文件,而VC++的图形库文件是#include <windows.h>,总之,好多都是在TC环境下用的 如果找不到,你就找对应的VC下的库把#include <...
贵溪市13597414562: c语言怎么样编写一个时钟程序 - ?
卓肃舒敏: c语言时钟程序代码如下:#include<windows.h>#include<math.h>#define ID_TIMER 1//计时器ID#define TWOPI (2*3.14159) LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); int WINAPI WinMain(HINSTANCE hInstance,...
贵溪市13597414562: 用c语言编一个时钟程序实现时分秒计时功能 - ?
卓肃舒敏: #include<stdio.h> #include<time.h>int main() {time_t t1,t2;struct tm *ptm;char timestr[128]={'\0'}; time(&t1);while(1){time(&t2);if(difftime(t2,t1)>=1){system("cls");ptm=localtime(&t2);strftime(timestr,128,"%H:%M:%S",ptm);printf("%s\n",timestr);t1=t2;}}system("PAUSE");return 0; }
贵溪市13597414562: 用C语言编一个时钟 程序 - ?
卓肃舒敏: /*全屏幕模拟时钟的c源程序*/#include<graphics.h>#include<math.h>#include<dos.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,...
贵溪市13597414562: C语言 用全局变量编程模拟显示一个数字式时钟 - ?
卓肃舒敏: \r 表示的是回车(不换行)啊,\b才表示退格
贵溪市13597414562: 诚求一个C语言程序:模拟时钟转动程序 - ?
卓肃舒敏: #include <stdio.h>#include <stdlib.h>#include <time.h>//#include <dos.h>#include <conio.h> int main() { struct tm *curtime; time_t t; clock_t start; double th_hour,th_min,th_sec; do { printf("*********************************************"); printf("** This is...
贵溪市13597414562: C语言 用devc++编写一个模拟时钟,最简单那种就行,但要能在devc++上运行. - ?
卓肃舒敏: #include using namespace std; class Clock{public:Clock(short h=0,short m=0,short s=0):h(h),m(m),s(s){}void displayTime();private:short h;short m;short s; };void Clock::displayTime(){while(true){cout< Sleep(1000);//一秒更新一次cout< if(...
贵溪市13597414562: C语言,计时器 - ?
卓肃舒敏: 秒表计时器的代码 #include <stdio.h> #include <conio.h> #include <windows.h> #include <stdlib.h> struct tm //定义时间结构体,包括时分秒和10毫秒 { int hours,minutes,seconds; int hscd; }time,tmp,total; //time用以计时显示,tmp用以存储上一阶段...