Advertisement
Md_hosen_zisad

integal

Jun 9th, 2019
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<math.h>
  3. double f(double x){
  4. return sin(x);
  5.  
  6. }
  7.  
  8. main(){
  9. int i,n ;
  10. double a, b, h, x,sum=0,integral;
  11. printf("enter the number of sub-interval:");
  12. scanf("%d ",&n);
  13. printf("enter the initial limit: ");
  14. scanf("%lf",&a);
  15. printf("enter the final limit:");
  16. scanf("%lf",&b);
  17. h=fabs(b-a)/n;
  18. for(i=1;i<n;i++){
  19. x=a+i*h;
  20. sum+=f(x);
  21. }
  22. integral=(h/2)*(f(a)+f(b)+2*sum);
  23. printf("\n The integral is :%lf\n",integral);
  24. return 0;
  25.  
  26.  
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement