c语言秒表程序_C / C ++程序创建数字秒表

这是一个简单的C++程序,用于构建一个数字秒表。初学者也能轻松理解。程序包括开始、暂停、重置和退出功能。只需将cout语句替换为printf,即可将其转换为C语言版本。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

c语言秒表程序

Hello friends, this is a simple program to create a digital stopwatch. I am sure that even a beginner can understand it very easily. I have written this in c++, so to use it c just change all cout statements with corresponding printf statements. I hope you understand what i want to say. If you have any kind of problem in doing this then let me know by commenting below, i will try my best to help you. So just try this and share your experience with me.

Also Read: C++ Program to create an Analog Clock
Also Read: C++ Hotel Management Project

#include<conio.h>
#include<process.h>
#include<iostream.h>
#include<dos.h>

int h=0,m=0,s=0,ms=0;
char ch=’p’;

void main()
{
void watch();
watch();

while(1)
{
if(kbhit())
ch=getch();
if(ch==’s’||ch==’S’)
break;
if(ch==’e’||ch==’E’)
exit(0);
}

while(1)
{
watch();
delay(10);

if(kbhit())
ch=getch();

if(ch==’r’||ch==’R’)
{
h=m=s=ms=0;
watch();

while(1)
{
if(kbhit())
ch=getch();
if(ch==’s’||ch==’S’)
break;
if(ch==’e’||ch==’E’)
exit(0);
}
}
else
if(ch==’p’||ch==’P’)
while(1)
{
if(kbhit())
ch=getch();
if(ch==’s’||ch==’S’)
break;
if(ch==’e’||ch==’E’)
exit(0);
if(ch==’r’||ch==’R’)
{
ch=’c’;
h=m=s=ms=0;
watch();
}
}
else
if(ch==’e’||ch==’E’)
exit(0);

if(ms!=99)
ms++;
else
{
ms=0;
if(s!=59)
s++;
else
{
s=0;
if(m!=59)
m++;
else
{
m=0;
h++;
}
}
}
}
}

void watch()
{
clrscr();
cout<<“nnnnntttt#############”;
cout<<“ntttt# Stopwatch #”;
cout<<“ntttt#############”;
cout<<“nntttt  “<<h<<“:”<<m<<“:”<<s<<“:”<<ms;

cout<<“nnnnnnnnntttttttPress Key”;
cout<<“nttttttt———“;
cout<<“nttttttts -> Start”;
cout<<“ntttttttp -> Pause”;
cout<<“ntttttttr -> Reset”;
cout<<“nttttttte -> Exit”;
}

Hello friends, this is a simple program to create a digital stopwatch. I am sure that even a beginner can understand it very easily. I have written this in c++, so to use it c just change all cout statements with corresponding printf statements. I hope you understand what i want to say. If you have any kind of problem in doing this then let me know by commenting below, i will try my best to help you. So just try this and share your experience with me.

Also Read: C++ Program to create an Analog Clock
Also Read: C++ Hotel Management Project

#include<conio.h>
#include<process.h>
#include<iostream.h>
#include<dos.h>

int h=0,m=0,s=0,ms=0;
char ch=’p’;

void main()
{
void watch();
watch();

while(1)
{
if(kbhit())
ch=getch();
if(ch==’s’||ch==’S’)
break;
if(ch==’e’||ch==’E’)
exit(0);
}

while(1)
{
watch();
delay(10);

if(kbhit())
ch=getch();

if(ch==’r’||ch==’R’)
{
h=m=s=ms=0;
watch();

while(1)
{
if(kbhit())
ch=getch();
if(ch==’s’||ch==’S’)
break;
if(ch==’e’||ch==’E’)
exit(0);
}
}
else
if(ch==’p’||ch==’P’)
while(1)
{
if(kbhit())
ch=getch();
if(ch==’s’||ch==’S’)
break;
if(ch==’e’||ch==’E’)
exit(0);
if(ch==’r’||ch==’R’)
{
ch=’c’;
h=m=s=ms=0;
watch();
}
}
else
if(ch==’e’||ch==’E’)
exit(0);

if(ms!=99)
ms++;
else
{
ms=0;
if(s!=59)
s++;
else
{
s=0;
if(m!=59)
m++;
else
{
m=0;
h++;
}
}
}
}
}

void watch()
{
clrscr();
cout<<“nnnnntttt#############”;
cout<<“ntttt# Stopwatch #”;
cout<<“ntttt#############”;
cout<<“nntttt  “<<h<<“:”<<m<<“:”<<s<<“:”<<ms;

cout<<“nnnnnnnnntttttttPress Key”;
cout<<“nttttttt———“;
cout<<“nttttttts -> Start”;
cout<<“ntttttttp -> Pause”;
cout<<“ntttttttr -> Reset”;
cout<<“nttttttte -> Exit”;
}

翻译自: https://www.thecrazyprogrammer.com/2013/06/cc-program-to-create-digital-stopwatch.html

c语言秒表程序

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值