Help! C programming...
#include <stdio.h>
#include <math.h>
#define NT double
NT f(NT x, NT y)
{
return x+y;
}
NT rkstep (NT (*func)(NT, NT), NT x, NT y[], NT h, int n, NT *err[])
{
NT k[n], y12[n], y1[n], k12[n];
k[n]=(*func)(x,y[n]);
y12[n]=y[n]+k[n]*h/2;
k12[n]=(*func)(x,y12[n]);
y1[n]=y[n]+k12[n]*h;
*err[n]=fabs(k[n]-k12[n])*h/2;
return y1[n];
}
int main ()
{
int n;
NT x, y[n], h, *err[n], result[n];
x=1;
y[0]=10;
for (n=0;n<4;n++)
{result[n]=rkstep(&f,x,y[n],h,n,&err[n]);
printf("n=%d\n", n);
printf("result=%lf\n\n", result[n]);
}
return 0;
}
#include <math.h>
#define NT double
NT f(NT x, NT y)
{
return x+y;
}
NT rkstep (NT (*func)(NT, NT), NT x, NT y[], NT h, int n, NT *err[])
{
NT k[n], y12[n], y1[n], k12[n];
k[n]=(*func)(x,y[n]);
y12[n]=y[n]+k[n]*h/2;
k12[n]=(*func)(x,y12[n]);
y1[n]=y[n]+k12[n]*h;
*err[n]=fabs(k[n]-k12[n])*h/2;
return y1[n];
}
int main ()
{
int n;
NT x, y[n], h, *err[n], result[n];
x=1;
y[0]=10;
for (n=0;n<4;n++)
{result[n]=rkstep(&f,x,y[n],h,n,&err[n]);
printf("n=%d\n", n);
printf("result=%lf\n\n", result[n]);
}
return 0;
}