#include <stdio.h>
#include <math.h>
double integrateF(double low, double high)
{
double low = 0;
double high = 20;
double delta_x=0;
double x, ans;
double s = 1/2*exp((-x*x)/2);
for(x=low;x<=high;x++)
delta_x = x+delta_x;
ans = delta_x*s;
return ans;
}
Run Code Online (Sandbox Code Playgroud)
它说低和高被"重新声称为不同类型的符号",我不知道这意味着什么.基本上,我在这里所做的一切(READ:尝试)是从低(我设置为0)到高(20)的积分,以找到黎曼和.for循环看起来有点像...我迷路了.
编辑:
#include <stdio.h>
#include <math.h>
double integrateF(double low, double high)
{
low = 0;
high = 20;
double delta_x=0;
double ans = 0;
double x;
double s = 1/2*exp((-x*x)/2);
for(x=low;x<=high;x++)
{
delta_x = x+delta_x;
ans = ans+(delta_x*s);
}
return ans; …Run Code Online (Sandbox Code Playgroud) 我知道虽然(1)是一个无限循环但是(i)意味着什么呢?
int i=5;
...
while(i)
{
i=i-1;
printf("%d\n", i);
}
Run Code Online (Sandbox Code Playgroud)
最后,将打印数字"0".我不明白的是为什么这不是一个无限循环,为什么它停在0?