Advertisement
J3st3rs_j0k3

dora_pr5_3

Nov 30th, 2021
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.53 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. #define N 30
  6.  
  7. double integral(double a, double b, int n, double (*f)(double)){
  8.     double s=(f(a)+f(b))/2;
  9.     double h=(b-a)/n;
  10.     for (int i=1; i<=n-1; i++)
  11.     {
  12.         s+=f(a+i*h);
  13.     }
  14.     return h*s;
  15. }
  16.  
  17. double f1(double x)
  18. {
  19.     return 2*x *(x*x + 1);
  20. }
  21.  
  22. double f2(double x)
  23. {
  24.     return log(x*x + 1);
  25. }
  26.  
  27. int main()
  28. {
  29.    
  30. printf("First integral = %.2lf\n", integral(-1, 4, N, f1));
  31. printf("Second integral = %.2lf\n", integral(1, 4, N, f2));
  32. return 0;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement