无限循环 [英] Infinite loop

查看:70
本文介绍了无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是一名数学家,我正在尝试编写一个程序来尝试我已经衍生出来的公式。但是,似乎我有一个

无限循环,我不太明白为什么。我希望有人

能指出我正确的方向。


代码:


#include< stdio.h>

#include< math.h>


int main()

{

float start = 0;

float end = 0;

float step = 0;

float x = 0;
>
float y = 0;


printf("输入起始值\ n");

scanf("%f" ;,& start);

printf("输入结束值\ n");

scanf("%f",& end);

printf("输入step \ n");

scanf("%f",& step);


for(x = start; x = end; x + = step){

y =(pow(260,.5)/ 130)* cos(2 * x-1.463)+( 67/20)* exp(x)+

(37/52)* exp(-3 * x);

printf("%3.3f%3.3f \ n",x,y);

}

}


谢谢,

戴夫

Hi all, I am a mathematician and I''m trying to write a program to try
out a formula that I''ve derived. However, it seems that I''ve got an
infinite loop and I don''t quite understand why. I was hoping someone
could point me in the right direction.

Code:

#include <stdio.h>
#include <math.h>

int main()
{
float start = 0;
float end = 0;
float step = 0;
float x = 0;
float y = 0;

printf("Enter the starting value\n");
scanf("%f", &start);
printf("Enter the ending value\n");
scanf("%f", &end);
printf("Enter the step\n");
scanf("%f", &step);

for(x=start;x=end;x+=step) {
y = (pow(260,.5)/130)*cos(2*x-1.463) + (67/20)*exp(x) +
(37/52)*exp(-3*x);
printf("%3.3f %3.3f\n",x,y);
}
}

Thanks,
Dave

推荐答案

< ; dm ****** @ cox.netwrote:
<dm******@cox.netwrote:

大家好,我是一名数学家,我正在尝试写一个程序来试试/>
我已经推导出一个公式。但是,似乎我有一个

无限循环,我不太明白为什么。我希望有人

能指出我正确的方向。


代码:


#include< stdio.h>

#include< math.h>


int main()

{

float start = 0;

float end = 0;

float step = 0;

float x = 0;
>
float y = 0;


printf("输入起始值\ n");

scanf("%f" ;,& start);

printf("输入结束值\ n");

scanf("%f",& end);

printf("输入step \ n");

scanf("%f",& step);


for(x = start; x = end; x + = step){
Hi all, I am a mathematician and I''m trying to write a program to try
out a formula that I''ve derived. However, it seems that I''ve got an
infinite loop and I don''t quite understand why. I was hoping someone
could point me in the right direction.

Code:

#include <stdio.h>
#include <math.h>

int main()
{
float start = 0;
float end = 0;
float step = 0;
float x = 0;
float y = 0;

printf("Enter the starting value\n");
scanf("%f", &start);
printf("Enter the ending value\n");
scanf("%f", &end);
printf("Enter the step\n");
scanf("%f", &step);

for(x=start;x=end;x+=step) {



您的意思是x ==结束?

Did you mean x==end ?


y =(pow(260,.5)/ 130)* cos(2 * x-1.463)+(67/20)* exp(x)+

(37/52)* exp(-3 * x);

printf("%3.3f%3.3f \ n",x,y);

}

}


谢谢,

Dave
y = (pow(260,.5)/130)*cos(2*x-1.463) + (67/20)*exp(x) +
(37/52)*exp(-3*x);
printf("%3.3f %3.3f\n",x,y);
}
}

Thanks,
Dave



3月17日晚上8:39,锇 < r124c4u ... @ comcast.netwrote:
On Mar 17, 8:39 pm, "osmium" <r124c4u...@comcast.netwrote:

< dmora ... @ cox.netwrote:
<dmora...@cox.netwrote:

大家好,我是一名数学家,我正在努力编写一个程序来尝试我已经衍生出来的公式。但是,似乎我有一个

无限循环,我不太明白为什么。我希望有人能够把我指向正确的方向。
Hi all, I am a mathematician and I''m trying to write a program to try
out a formula that I''ve derived. However, it seems that I''ve got an
infinite loop and I don''t quite understand why. I was hoping someone
could point me in the right direction.


代码:
Code:


#include< stdio.h>

#include< math.h>
#include <stdio.h>
#include <math.h>


int main()

{

float start = 0;

float end = 0;

float step = 0;

float x = 0;

float y = 0;
int main()
{
float start = 0;
float end = 0;
float step = 0;
float x = 0;
float y = 0;


printf("输入起始值\ n");

scanf("%f", & start);

printf("输入结束值\ n");

scanf("%f",& end);

printf("输入step \ n");

scanf("%f",& step);
printf("Enter the starting value\n");
scanf("%f", &start);
printf("Enter the ending value\n");
scanf("%f", &end);
printf("Enter the step\n");
scanf("%f", &step);


for(x = start; x = end; x + = step){
for(x=start;x=end;x+=step) {



你的意思是x ==结束?


Did you mean x==end ?


y =(pow(260,.5)/ 130)* cos(2 * x-1.463)+(67 / 20)* exp(x)+

(37/52)* exp(-3 * x);

printf("%3.3f%3.3f \ n",x,y);

}

}
y = (pow(260,.5)/130)*cos(2*x-1.463) + (67/20)*exp(x) +
(37/52)*exp(-3*x);
printf("%3.3f %3.3f\n",x,y);
}
}


谢谢,

Dave
Thanks,
Dave



停止了无限循环,但现在,它在输入后停止了
$ b输入$ b。


Dave

That stopped the infinite loop, but now, it''s stopping after the input
is entered.

Dave


dm ****** @ cox.net 写道:

大家好,我是数学家
Hi all, I am a mathematician



你有没有在一篇文章中用这个完全相同的短语开始

前。我记得,它启动了一个火焰线程。

Didn''t you start out with this exact same phrase in a post some time
ago. As I recall, it start a flame thread.


我正在尝试编写一个程序来尝试

的公式我已经派生了。但是,似乎我有一个

无限循环,我不太明白为什么。我希望有人

能指出我正确的方向。


代码:


#include< stdio.h>

#include< math.h>


int main()

{

float start = 0;

float end = 0;

float step = 0;

float x = 0;
>
float y = 0;
and I''m trying to write a program to try
out a formula that I''ve derived. However, it seems that I''ve got an
infinite loop and I don''t quite understand why. I was hoping someone
could point me in the right direction.

Code:

#include <stdio.h>
#include <math.h>

int main()
{
float start = 0;
float end = 0;
float step = 0;
float x = 0;
float y = 0;



除非你有充分的理由,否则你可以考虑对这些

对象使用double。它提供了更高的默认精度。

Unless you''ve good reasons, you might consider using double for these
objects. It provides greater default precision.


printf("输入起始值\ n");

scanf("%f" ;,& start);

printf("输入结束值\ n");

scanf("%f",& end);

printf("输入step \ n");

scanf("%f",& step);


for(x = start; x = end; x + = step){
printf("Enter the starting value\n");
scanf("%f", &start);
printf("Enter the ending value\n");
scanf("%f", &end);
printf("Enter the step\n");
scanf("%f", &step);

for(x=start;x=end;x+=step) {



=运算符是赋值运算符。您可能意味着< =或<

或其他一些关系或逻辑关系。否则测试

只是将结束赋给x并评估x。如果x不是零,则

循环将继续。因此,如果用户输入了正或负的
值,程序将进入无限循环。

The = operator is the assignment operator. You probably meant <= or <
or some other relational or logical relation. Otherwise the test
simply assigns end to x and evaluates x. If x is other than zero, the
loop will continue. So if the user had entered a positive or negative
value for end, the program will enter an infinite loop.


y =(pow( 260,.5)/ 130)* cos(2 * x-1.463)+(67/20)* exp(x)+(37/52)* exp(-3 * x);
y = (pow(260,.5)/130)*cos(2*x-1.463) + (67/20)*exp(x) + (37/52)*exp(-3*x);



不匹配的括号。如果你没有剪切和粘贴

无法编译或运行的确切代码,那么它一直在猜测。


你应该将上述陈述分成多个步骤,暂时或两个为b $ b。通过重新排序,您可以保持更高的准确性和

增强可读性。

Mismatched parenthesis. If you don''t cut and paste the exact code that
failed to compile or run, then it''s guessing all the way.

You should split up the above statement into multiple steps, with a
temporary or two. By reordering it you can preserve more accuracy and
enhance readability.


printf("%3.3f%3.3f \ n" ,x,y);

}

}
printf("%3.3f %3.3f\n",x,y);
}
}


这篇关于无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆