1. c语言中如何编写以秒为单位的计时函数求代码

//使用windows的延时函数Sleep();实现
//以下代码实现每秒钟输出一个数字,连续输出10个
#include<windows.h>
#include<stdio.h>

//主函数
voidmain()
{
inti=0;
while(i<10)
{
printf("%d ",i++);
Sleep(1000);
}
}


还可以使用多媒体定时器实现精确延时,详细请网络《精确延时的实现》

2. 在c语言程序中如何编辑秒数,让它按小时;分钟,秒的形式输出

根据输入的秒数,转换成相应的时,分,秒数据输出过程为:

  1. 定义变量h, m, s来存储转换结果

  2. 定义seconds变量,接收用户输入

  3. 得到小时数:h=seconds/3600;

  4. 去除小时数:seconds%=3600;

  5. 得到分钟数:m=seconds/60;

  6. 得到秒数:s=seconds%60 ;

  7. 输出结果

参考代码:

#include<stdio.h>
intmain()
{
inth,m,s,seconds;
printf("inputsec:");scanf("%d",&seconds);
h=seconds/3600;
seconds%=3600;
m=seconds/60;
s=seconds%60;
printf("%d:%d:%d ",h,m,s);
return0;
}
运行结果:
inputsec:14567
4:2:47

3. C语言定时1.5秒函数怎么写

可能不是你最想要的,但是可以大致满足你的要求。
另外还可以借助DOS的at命令进行计划任务。

#include <stdio.h>
#include <conio.h>
#include <time.h>
#include <dos.h>

main()
{
int HourWant=22;
int MinWant=31;
/*22点31分输出信息*/

struct time t;

while(1)
{
gettime(&t);
if (t.ti_hour==HourWant && t.ti_min==MinWant)
{
printf("time is up.");
break;
}
sleep(1); /*Delay for 1 second*/
}
getch();
}

4. C语言秒的转换

根据输入的秒数,转换成相应的时,分,秒数据输出过程为:定义变量h,m,s来存储转换结果定义seconds变量,接收用户输入得到小时数:h=seconds/3600;去除小时数:seconds%=3600; 得到分钟数:m=seconds/60;得到秒数:s=seconds%60;输出结果参考代码:#includeint main(){ int h,m,s,seconds; printf("input sec: ");scanf("%d", &seconds ); h=seconds/3600; seconds %= 3600 ; m=seconds/60; s=seconds%60; printf("%d:%d:%d\n", h,m,s ); return 0;}运行结果:input sec: 145674:2:47

5. c语言5秒延时程序怎么编写 要求精确的!

for循环不够精确

你可以读出当前系统的时间

还是用for循环,顺延5秒后结束循环

6. c语言中有没有_sleep函数

因为C语言中本身就有sleep函数,声明头文件为头文件#include <unistd.h>,
Sleep()单位为毫秒,sleep()单位为秒(如果需要更精确可以用usleep单位为微秒)

7. C语言如何隔几秒再显示下一句话

  1. C语言的库函数中提供了时间延迟函数

  2. 时间延迟函数的函数名: delay

功 能: 将程序的执行暂停一段时间(毫秒)
用 法: void delay(unsigned
milliseconds);
程序例:
/* Emits a 440-Hz tone for 500 milliseconds */

#include <dos.h>

int main(void)
{
sound(440);
delay(500);
nosound();

return 0;
}