Advertisement
Guest User

Untitled

a guest
Feb 19th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. double integral(double a, double b, int n, double (*fp)(double)){
  4. double h, sum;
  5.  
  6. h = (b-a) / n;
  7. sum = ((*fp)(a) + 4*(*fp)(a+h)+2*(*fp)(a+2*h));
  8.  
  9. int j;
  10.  
  11. for(j = 1; j < n; j++){
  12. sum += (2*(*fp)(a+(j-1)*h))+(4*(*fp)(a+j*h))+(*fp)(b) ;
  13. }
  14.  
  15. return h/3 * sum;
  16. }
  17.  
  18. double quadratic(double x)
  19. {
  20. return x*x + 5.0*x + 3.0;
  21. }
  22.  
  23. int main()
  24. {
  25.  
  26. while(1)
  27. {
  28. double x;
  29. double a,b;
  30. printf("Input batas bawah integral = ");
  31. scanf("%lf",&a);
  32. printf("\n");
  33.  
  34. printf("Input batas atas integral = ");
  35. scanf("%lf",&b);
  36. printf("\n");
  37.  
  38. printf("Input variabel n = ");
  39. scanf("%lf",&x);
  40. printf("\n");
  41.  
  42.  
  43. // if(x%2==0){
  44. printf("%.2lf\n",integral(a, b, x, quadratic));
  45. // }
  46.  
  47. // else{
  48. // printf("Variabel n harus berbentuk angka genap\n");
  49. // }
  50. }
  51.  
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement