diff options
Diffstat (limited to 'test/c/integr.c')
-rw-r--r-- | test/c/integr.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/c/integr.c b/test/c/integr.c new file mode 100644 index 00000000..abcbd28d --- /dev/null +++ b/test/c/integr.c @@ -0,0 +1,23 @@ +static double square(double x) +{ + return x * x; +} + +static double integr(double (*f)(double), double low, double high, int n) +{ + double h, x, s; + int i; + + h = (high - low) / n; + s = 0; + for (i = n, x = low; i > 0; i--, x += h) s += f(x); + return s * h; +} + +double test(int n) +{ + return integr(square, 0.0, 1.0, n); +} + + + |