www.zt blg.com:这个程序这么让它循环运行啊

来源:百度文库 编辑:高校问答 时间:2024/04/29 12:57:40
main()
{float n,b,result;
result=0,b=2;
printf("this program can compute the sum of the even numbers from 0 to 'n'\n");
printf("please type in the num 'n'=");
scanf("%f",&n);
while (b<=n)
{
result=result+b;
b=b+2;
}
printf("result=%f",result);
}
就是算了一次后在算一次,谢谢

main()
{float n,b,result;
char opt;
result=0,b=2;
while(1){
printf("this program can compute the sum of the even numbers from 0 to 'n'\n");
printf("please type in the num 'n'=");
scanf("%f",&n);
while (b<=n)
{
result=result+b;
b=b+2;
}
printf("result=%f",result);
ask:
printf("wanna one more time?Y/N:\n");
scanf("%c", &opt);
switch(opt){
case Y:
case y:
break;
case N:
case n:
goto end;
default:
goto ask;
}
}
end:
printf("This ends the program\n");
}

设一个while循环适一下