/* This version is more robust because it does not rely on the first point plotted being for x=0. Formula_plot is responsible for getting the pen into the right place to start the graph, then calling on another function to do the plotting. Formula_plot_rest does all the plotting in exactly the same way as the previous version, but without having to worry about whether to draw_to or move_to */ #include "library.h" double f(double x) { const double A = x*x*x/1e6; return cos(A)*1e4/(x+1) + 250; } void formula_plot_rest(int A, int B) { const int x = A; const int y = f(x); draw_to(x, y); if (A < B) formula_plot_rest(A+1, B); } void formula_plot(int A, int B) { const int x = A; const int y = f(x); move_to(x, y); if (A < B) formula_plot_rest(A+1, B); } void main() { make_window(500, 500); formula_plot(100, 500, f); }