Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<math.h>
- double f(double x){
- return sin(x);
- }
- main(){
- int i,n ;
- double a, b, h, x,sum=0,integral;
- printf("enter the number of sub-interval:");
- scanf("%d ",&n);
- printf("enter the initial limit: ");
- scanf("%lf",&a);
- printf("enter the final limit:");
- scanf("%lf",&b);
- h=fabs(b-a)/n;
- for(i=1;i<n;i++){
- x=a+i*h;
- sum+=f(x);
- }
- integral=(h/2)*(f(a)+f(b)+2*sum);
- printf("\n The integral is :%lf\n",integral);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement