可以参考下面的代码:
#include <stdio.h>
#include <conio.h>
#include <windows.h>
main( )
{
int p
while( ! _kbhit() ) {
// run progs
_cputs( "Please hit me ! \n" )
Sleep(500)
}
return 0
}
扩展资料:
kbhit()是一个C和C++函数,用于非阻塞地响应键盘输入事件。
函数名:kbhit()
功能及返回值: 检查当前是否有键盘输入,若有则返回一个非0值,否则返回0。
用 法:int kbhit(void)
C++语言包含头文件: include <conio.h>。
C语言不需包含额外头文件。
在VC++6.0下为_kbhit()
功能及返回值同上。
参考资料来源:百度百科-kbhit
你好!!
可以采用goto的语句完成,看效果:
完整的代码:
#include <stdio.h>int main()
{
float x,y
char a='y'
jixu:printf("请输入:")
scanf("%f",&x)
getchar()
if(x>=1)
if(x>=1&&x<10)
y=2*x-1
else
y=3*x-11
else
y=x
printf("%f\n",y)
printf("y 继续,其它键退出")
if(getchar()=='y')
goto jixu
return 0
}
#include<stdio.h>
int
main(void)
{
char
c
printf("Ok\n")
printf("Continue?(Y/y)
")
scanf("
%c",&c)
/*
如果是Y,则递归调用主函数,实现再运行一次*/
if
(c=='y'
||
c=='Y')
{
main()
/*
调用main(),因为main也是函数,不过很少这样用!*/
}
return
0
/*
其它的输入均结束*/
}
慢慢学吧,以后懂的方法会更多的哦!