Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #define N 10000
- #define M 100000
- typedef double (*dfunc)(double);
- static double quad_trap(dfunc f, double a, double b, unsigned int n)
- {
- double h = (b - a) / n;
- double res = 0.5 * (f(a) + f(b));
- for (unsigned int i = 1; i < n; i++)
- res += f(a + i * h);
- return res * h;
- }
- static double f(double x)
- {
- return exp(x) - 10.0;
- }
- int main()
- {
- double s = 0;
- for (int i = 0; i < M; i++) {
- s = quad_trap(f, -1.0, 1.0, N);
- }
- printf("%u %u %.18f \n", N, M, s);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement