當前位置:首頁 » 編程語言 » c語言怎麼讓程序循環運行多次
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言怎麼讓程序循環運行多次

發布時間: 2022-05-02 14:06:32

㈠ 用c語言編了個程序,怎樣才能讓它在運行窗口中多次運行呢

#include<stdio.h>
int main()
{
while(1) //設置一個死循環,使程序重復運行
{
system("cls"); //清屏,清除窗口上之前的輸出
int a,b;
printf("請輸入兩個加數:");
scanf("%d%d",&a,&b);
printf("兩數之和為%d",a+b);
getch(); //按任意鍵從頭開始
}
}

㈡ 怎樣讓c語言程序重復執行

例如:

#include<stdio.h>

intmain(void)

{

charc;

c=getchar();

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

{

printf("%c",c);//這里改成你需要的那個函數做相應的工作就可以了

c=getchar();

}

return0;

}

(2)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語言程序,如何讓它循環運行。大神修改下代碼。

以下是你要的代碼
#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語言如何循環運行程序

c語言中用於循環運行程序的結構有三種,分別是:
①for(表達式1;表達式2;表達式3){循環體}
表達式1,是初始化條件,如i=0。
表達式2,循環條件,滿足就繼續執行循環體,不滿足就跳出循環。
表達式3,這個一般是改變循環條件的地方,如i++。
參考代碼:
#include<stdio.h>
int main()//for循環計算1到10累加和
{
int i,sum=0;
for (i=0;i<=10;i++)
sum+=i;

printf("%d\n",sum);
return 0;
}
/*
運行結果:
55
*/
②while(表達式){循環體}
表達式的值為真(非0)時,
執行循環體語句。
參考代碼:
#include<stdio.h>
int main()//while循環計算1到10累加和
{
int i,sum=0;
while(i<=10) {
sum+=i;
i++;
}

printf("%d\n",sum);
return 0;
}
/*
運行結果:
55
*/
③ do{循環體} while(表達式);
先執行循環中的語句,然後再判斷表達式是否為真,
如果為真則繼續循環;否則,
則終止循環。
參考代碼:
#include<stdio.h>
int main()//do……while循環計算1到10累加和
{
int i,sum=0;
do{
sum+=i;
i++;
} while(i<=10);

printf("%d\n",sum);
return 0;
}
/*
運行結果:
55
*/

㈤ C語言中,怎麼讓程序重復運行(要求是否退出Y/N)

用一個while語句即可
如:
int
a=1;
while(a=1){
//1執行0退出
……
//要執行的語句
cin>>x;
//輸入1或0
a=x;
}

㈥ 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語言中怎麼讓程序多次執行

你好!!

可以採用goto的語句完成,看效果:

#include<stdio.h>
intmain()
{
floatx,y;
chara='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 ",y);

printf("y繼續,其它鍵退出");
if(getchar()=='y')
gotojixu;
return0;
}