当前位置:首页 » 编程语言 » c语言怎样让程序一直运行
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言怎样让程序一直运行

发布时间: 2022-07-06 21:08:38

c语言中,怎么让程序重复运行(要求是否退出Y/N)

用一个while语句即可
如:
int
a=1;
while(a=1){
//1执行0退出
……
//要执行的语句
cin>>x;
//输入1或0
a=x;
}

❷ C语言里面怎样使一个程序一直循环运行

看你的循环用来干嘛的,举例一个for循环的写法:
int
n;
while(1){
scanf("%d",&n);
if(n==0)break;
int
sum=0;
for(int
i=1;i<=n;i++){sum=sum+i;}
printf("sum=%d\n",sum);
}
最后的结果就是得出1加到n的值,而且程序会一直让你输入一个n,直到你输入一个0程序就跳出了~!

❸ C语言怎样使程序一直进行

把计算及读取数据的这个过程都放在while中,每次读取数据前判定是否为quit

❹ 我写了一个C语言程序,如何让它循环运行。大神修改下代码。

以下是你要的代码
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int
main()
{

char
cmd[20]="shutdown
-s
-t
";

char
t[5]="0";

int
c;

system("title
C语言关机程序");
//设置cmd窗口标题

system("mode
con
cols=37
lines=14");
//窗口宽度高度

system("color
f0");
//可以写成
red
调出颜色组

system("date
/T");

system("TIME
/T");

printf("-----------
C语言关机程序
-----------\n");

printf("1.实现15分钟内定时关闭计算机\n");

printf("2.立即关闭计算机\n");

printf("3.注销计算机\n");

printf("4.取消定时关机\n");

printf("5.检查更新");

printf("6.退出系统\n");

printf("------------
By--QHnan
-------------\n");

puts("

版本号:1.00.34");
while(1)
{

scanf("%d",&c);

switch(c)
{

case
1:

printf("您想在多少秒后自动关闭计算机?为60的倍数。(0~900)\n");

scanf("%s",t);

system(strcat(cmd,t));

case
2:

system("shutdown
-p");

case
3:

system("shutdown
-l");

case
4:

system("shutdown
-a");

case
6:

break;

default:

printf("Error!\n");

case
5:

puts("更新网址:");

puts("https://pan..com/share/home?

uk=2690678049#category/type=0");

}
}

system("pause");

return
0;
}

❺ 怎样让c语言程序重复执行

例如:

#include<stdio.h>

intmain(void)

{

charc;

c=getchar();

while(c!='')//输入空格退出

{

printf("%c",c);//这里改成你需要的那个函数做相应的工作就可以了

c=getchar();

}

return0;

}

(5)c语言怎样让程序一直运行扩展阅读

C语言循环控制语句

#include<stdio.h>

intmain(){

inta;

/*forloopexecution*/

for(a=10;a<20;a=a+1)

{

printf("valueofa:%d ",a);

}

return0;

}

C编程语言中do...while循环的语法是-

do{

statement(s);

}while(condition);

❻ C语言一个程序如何重复运行知道操作者想停止为止

方法如下:

system("pause");
会提示:
press any key to continue // 按任意一个键继续
你一开始运行就要暂停?
================================================
C语言中 如何使一个程序循环使用直到你想退出?
答:
如果你想 不断循环, 直到按了任何一个键 就退出:
#include <conio.h>
#include<stdio.h>
.....
void main()
{
int i;
while (!_kbhit()) {
// 程序内容放在这里,例如:
for (i=0;i<100000;i++) if (i %1000 == 0) printf("wait ");
}
-----------------------------------------------------------
如果你想 不断循环, 直到按了S 键 才退出:
int i;
char c;
Lab1:
for (i=0;i<100000;i++) if (i %1000 == 0) printf("wait ");
if (!_kbhit()) goto Lab1; // 判断是否按了键,没按,就无限循环
c = getchar(); // 如果按了,看是什么键
if (c != 'S' ) goto Lab1; // 不是 S 键, 则回去循环。

❼ C语言中,怎么让程序重复运行

重复执行用循环就可以了..呵呵
例如:
#include
int
main(void)
{
char
c;
c
=
getchar();
while(c!='
')//输入空格退出
{
printf("%c",
c);//这里改成你需要的那个函数做相应的工作就可以了
c
=
getchar();
}
return
0;
}

❽ C语言如何让程序一直不断运行直到按了某个键以后停止,代码怎么写

可以参考下面的代码:

#include <stdio.h>

#include <conio.h>

#include <windows.h>

main( )

{

int p;

while( ! _kbhit() ) {

// run progs

_cputs( "Please hit me ! " );

Sleep(500);

}

return 0;

}

(8)c语言怎样让程序一直运行扩展阅读:

kbhit()是一个C和C++函数,用于非阻塞地响应键盘输入事件。

函数名:kbhit()

功能及返回值: 检查当前是否有键盘输入,若有则返回一个非0值,否则返回0。

用 法:int kbhit(void);

C++语言包含头文件: include <conio.h>。

C语言不需包含额外头文件。

在VC++6.0下为_kbhit()

功能及返回值同上。

❾ C语言中写完的程序如何让他循环运行

/*针对你的补充,做了如下修改。应该符合你的心意。依据dos画面的大小,亲自给你调整了,循环次数和清屏操作。
*/
#include<stdio.h>
#include<stdlib.h> //rand()
#include<time.h> //srand()
void main()
{
//定义变量
int pc,quan;
int i=0; //added by ppliang0415
//给变量赋值

while(1){ //added by ppliang0415
//使每一次产生的数不同
srand((unsigned)time(NULL));
//产生1--3之间的一个数
pc=rand()%(3-1+1)+1;
printf("%d\n",pc);

//
printf("请出拳:");
scanf("%d",&quan);

if(quan==1||quan==2||quan==3)
{
//比较
if(pc==1) //计算机出石头
{
if(quan==1)
{
printf("平了\n");
}
else if(quan==2)
{
printf("计算机胜\n");
}
else if(quan==3)
{
printf("我胜\n");
}
}
else if(pc==2)//计算机出剪子
{
if(quan==1)
{
printf("我胜\n");
}
else if(quan==2)
{
printf("平了\n");

}
else if(quan==3)
{
printf("计算机胜\n");
}
}
else//计算机出布
{
if(quan==1)
{
printf("机胜\n");
}
else if(quan==2)
{
printf("我胜\n");
}
else if(quan==3)
{
printf("平了\n");
}
}
}
else
{
printf("请输入1,2,3\n\a\a");
}
i++; //added by ppliang0415
if(i==7)//added by ppliang0415
{system("cls"); //added by ppliang0415
i=0;}//added by ppliang0415
}//added by ppliang0415
}

❿ c语言如何循环运行程序

#include<stdio.h>

intmain(void)
{
intx;
doubley;
while(1)
{
printf("请输入你的门店营业额:");
scanf("%d",&x);
if(x<=100)
{
printf("该门店您没有利润

");
}
elseif(x>100&&x<=500)
{
y=(x-100)*0.0055;
printf("%lf",y);
}elseif(x>500&&x<=1000)
{
y=(x-500)*0.05+2.2;
printf("%lf",y);
}elseif(x>1000&&x<=4000)
{
y=(x-1000)*0.0045+2.5+2.2;
printf("%lf",y);
}elseif(x>4000&&x<=30000)
{
y=(x-4000)*0.0035+13.5+2.5+2.2;
printf("%lf",y);
}elseif(x>30000&&x<=100000)
{
y=(x-30000)*0.0025+91+13.5+2.5+2.2;
printf("%lf",y);
}elseif(x>100000&&x<=1000000)
{
y=(x-100000)*0.0005+175+91+13.5+2.5+2.2;
printf("%lf",y);
}elseif(x>1000000&&x<=8000000)
{
y=(x-60000)*0.35+6000+5000+3000+450+30+25;
printf("%lf",y);
}elseif(x>8000000&&x<=10000000)
{
y=(x-80000)*0.4+7000+6000+5000+3000+450+30+25;
printf("%lf",y);
}else
{
y=(x-10000)*0.45+8000+7000+6000+5000+3000+450+30+25;
printf("%lf",y);
}
}

return0;
}