Advertisement
Guest User

Untitled

a guest
May 24th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. double f(double x)
  5. {
  6. return sin(x);
  7. }
  8.  
  9. int main()
  10. {
  11. int N;
  12. printf("Specify N: ");
  13. scanf("%i",&N);
  14.  
  15. double h;
  16. h = M_PI/N;
  17.  
  18. double sum = 0;
  19.  
  20. double x;
  21. x=h;
  22.  
  23. for(int i=0;i<=N;i++)
  24. {
  25. if (i==0)
  26. {
  27. sum+=7*f(0);
  28. }
  29. if (i==N)
  30. {
  31. sum+=7*f(M_PI);
  32. }
  33. if (i==2 || i==(N-2))
  34. {
  35. sum+=12*f(x);
  36. x+=h;
  37. }
  38. if (i==1 || i==3 || i==(N-1) || i==(N-3))
  39. {
  40. sum+=32*f(x);
  41. x+=h;
  42. }
  43. if (i>=4 && i<=(N-4))
  44. {
  45. sum+=14*f(x);
  46. x+=h;
  47. }
  48. }
  49.  
  50. double result = ((2*h)/45)*sum;
  51. printf("The Boole rule method result for %i is %.10lf",N,result);
  52.  
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement