Advertisement
andruhovski

prog0108-demo

Sep 9th, 2014
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <math.h>
  3. double f1(double x)
  4. {
  5.     return x*x;
  6. }
  7. double f2(double x)
  8. {
  9.     return x*x*x;
  10. }
  11. double integral2(double a, double b, int n, double (*f) (double))
  12. {
  13.     double INTGRL = 0.0;
  14.     double h = double((b - a) / n);
  15.     for (double x = a; x <= b; x += h)
  16.     {
  17.         INTGRL += f(x - h / 2);
  18.     }
  19.     return INTGRL *= h;
  20. }
  21. int _tmain(int argc, _TCHAR* argv[])
  22. {
  23.     double a, b; int n;
  24.     scanf_s("%lf %lf %d", &a, &b, &n);
  25.     printf("%lf", integral2(a,b,n,sin));
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement