Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #define N 30
- double integral(double a, double b, int n, double (*f)(double)){
- double s=(f(a)+f(b))/2;
- double h=(b-a)/n;
- for (int i=1; i<=n-1; i++)
- {
- s+=f(a+i*h);
- }
- return h*s;
- }
- double f1(double x)
- {
- return 2*x *(x*x + 1);
- }
- double f2(double x)
- {
- return log(x*x + 1);
- }
- int main()
- {
- printf("First integral = %.2lf\n", integral(-1, 4, N, f1));
- printf("Second integral = %.2lf\n", integral(1, 4, N, f2));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement