/* This is a demonstration program for writing stuff in C To compile: gcc -o grid0 grid0.c -lm ^^^ "links to" library libm.a */ #include /* I/O library (actually, "prototypes" in this case) */ #include /* standard math library */ main() { float x=2; float y; y = exp(-pow(x,2.0)/2.0); printf("The value is %8.4f\n", y); } ======================================================================= /* This is a demonstration program for writing stuff in C To compile: gcc -o grid1 grid1.c -lm ^^^ "links to" library libm.a */ #include /* I/O library (actually, "prototypes" in this case) */ #include /* standard math library */ main() { float x; float y; int i; int imax; float ymax; for (i=0;i<21;i++) { x = -1.0 + (i/10.0); /* Note: x = -1.0 + (i/10); doesn't produce the right answer, because of "default" type coercion */ y = exp(-pow(x,2.0)/2.0); printf("The value at %8.4f is %8.4f\n", x, y); } } /* This is a demonstration program for writing stuff in C To compile: gcc -o grid2 grid2.c -lm ^^^ "links to" library libm.a */ #include /* I/O library (actually, "prototypes" in this case) */ #include /* standard math library */ typedef float real; real fcn(real x) { real y; y = exp(-pow(x,2.0)/2.0); return(y); } main() { real x; real y; real g[21]; int i; int imax = -1; real ymax = -10; for (i=0;i<21;i++) { g[i] = -1.0 + (i/10.0); /* Note: g[i] = -1.0 + (i/10); doesn't produce the right answer, because of "default" type coercion */ /* y = exp(-pow(g[i],2.0)/2.0); */ y = fcn(g[i]); printf("The value at %8.4f is %8.4f\n", g[i], y); if (ymax