c语言关于if结构的问题?

Python042

c语言关于if结构的问题?,第1张

#include <stdio.h>

int main()

{

int breathe, pulse

printf("Breathe: ")

scanf("%d", &breathe)

printf("Pulse: ")

scanf("%d", &pulse)

if (15 <= breathe &&breathe <=20

&&50 <= pulse &&pulse <= 70)

printf("sleeping\n")

else

printf("pretend\n")

return 0

}

使用要带上头文件:

#include <windows.h>

Sleep函数:

功 能: 执行挂起一段时间  

用 法: unsigned sleep(unsigned seconds) 

注意:  

1.在VC中使用带上头文件#include <windows.h>,在Linux下,gcc编译器中,使用的头文件因gcc版本的不同而不同#include <unistd.h> 

2.在VC中,Sleep中的第一个英文字符为大写的"S" ,在linux下不要大写,在标准C中是sleep, 不要大写,简单的说VC用Sleep, 别的一律使用sleep。

3.在VC中,Sleep()里面的单位,是以毫秒为单位,所以如果想让函数滞留1秒的话,应该是Sleep(1000)在Linux下,sleep()里面的单位是秒,而不是毫秒。

示例:

#include<stdio.h>

#include <windows.h> 

int main()  

{  

int a=100  

Sleep(3000) 

printf("%d",a)

return 0

} 

usleep函数:

功能: usleep功能把进程挂起一段时间, 单位是微秒us(百万分之一秒)。

语法: void usleep(int micro_seconds)

返回值: 无

注意:这个函数不能工作在 Windows 操作系统中。

usleep() 与sleep()类似,用于延迟挂起进程。进程被挂起放到reday queue。只是一般情况下,延迟时间数量级是秒的时候,尽可能使用sleep()函数。且此函数已被废除,可使用nanosleep。 

如果延迟时间为几十毫秒,或者更小,尽可能使用usleep()函数。这样才能最佳的利用CPU时间。

delay函数: 

功 能: 将程序的执行暂停一段时间,单位是毫秒ms(千分之一秒)  

用 法: void delay(unsigned milliseconds) 

示例:

#include<dos.h> 

int main(void)  

{  

sound(440) 

delay(500) 

nosound() 

return 0 

}

delay()是循环等待,该进程还在运行,占用处理器。

sleep()不同,它会被挂起,把处理器让给其他的进程。