#include "library.h" /* sin(x) = x/1 - x^3/6 + x^5/120 - x^7/5040 ..... factorial(0) = 1 factorial(N) = N * factorial(N-1), where N > 0 */ double factorial(const int N) { if (N == 0) return 1.0; else return N * factorial(N-1); } double sine(const double x) { const double t1 = x/1.0; const double t2 = t1 - x*x*x/6.0; const double t3 = t2 + pow(x, 5) / 120.0; const double t4 = t3 - pow(x, 7) / 5040.0; const double t5 = t4 + pow(x, 9) / factorial(9); const double t6 = t5 - pow(x, 11) / factorial(11); return t6; } void plot(const double x, const double maxx) { const double y = sine(x); if (x == 0.0) move_to(x * 90, 300 - 300 * y); else draw_to(x * 90, 300 - 300 * y); if (x < maxx) plot(x+0.01, maxx); } void plot2(const double x, const double maxx) { const double y = sin(x); if (x == 0.0) move_to(x * 90, 300 - 300 * y); else draw_to(x * 90, 300 - 300 * y); if (x < maxx) plot2(x+0.01, maxx); } void main() { make_window(600, 600); const double pi = acos(-1.0); plot(0.0, 2 * pi); plot2(0.0, 2 * pi); }