copy paste 的时候 有问题,再改一下#include
#include
#define NT double
NT f(NT x, NT y)
{
return x+y;
}
NT rkstep (NT x, NT y, NT h, NT *err_i)
{
NT k, y12, y1, k12;
k = f(x,y);
y12 = y + k*h/2;
k12 = f(x, y12);
y1 = y + k12*h;
*err_i = fabs(k-k12)*h/2;
return y1;
}
int main ()
{
int i = 0; // for loop index
NT x = 1;
NT h = 1; // what is the value of "h" ?
// dynamic sized arrays, (actually these are pointers)
NT *y;
NT *err;
NT *result;
int bound = 4; // "bound" is the size of your array
x=1;
// allocate memory for pointers
y = (NT*) malloc(bound*sizeof(NT));
err = (NT*) malloc(bound*sizeof(NT));
result = (NT*) malloc(bound*sizeof(NT));
// ensure memory allocation is successful
if(y == NULL || err == NULL || result == NULL)
{
printf("malloc() error: y, error or result!");
return 0;
}
y[0]=10;
for (i=0; i
奇怪……malloc and free
需要include什么library么?