fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. double func(double x) {
  5. return x * sin(x / 2.0);
  6. }
  7.  
  8. int main() {
  9. int n = 10000;
  10. double b = 3.1415926;
  11. double h = b / n;
  12. double s = 0.0;
  13.  
  14. for (int _ = 0; _ < 1000; _++) {
  15. s = 0.0;
  16. for (int i = 0; i < n; i++)
  17. s += func(h * i);
  18. }
  19.  
  20. printf("%lf\n", s * h);
  21. }
Success #stdin #stdout 0.19s 5280KB
stdin
Standard input is empty
stdout
3.999506