❶ 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;
}