fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <time.h>
  4.  
  5. double func(double x) {
  6. return x * sin(x * 0.5);
  7. }
  8.  
  9. int main() {
  10. double b = 3.1415926;
  11. const int n = 10000;
  12. const double h = b / n;
  13. const double c = 0.5 * h;
  14.  
  15. clock_t start, end;
  16. double total_time = 0.0;
  17.  
  18. for (int j = 0; j < 10000; j++) {
  19. double s = func(b);
  20. double x = h;
  21.  
  22. for (int i = 1; i < n; i += 2) {
  23. s += 2.0 * (func(x) + func(x + h));
  24. x += 2.0 * h;
  25. }
  26. s *= c;
  27. }
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty