Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- float f(float x)
- {
- return (1.0/(1+x*x));
- }
- int main()
- {
- int i,n;
- float h,xn,x0,a,sum,temp;
- printf("\nEnter the upper and lower limits");
- scanf("%f %f",&xn,&x0);
- printf("\nEnter the no of intervals");
- scanf("%d",&n);
- printf("\n\na\t\tf(a)");
- h=(xn-x0)/n;
- sum=f(x0)+f(xn);
- for(i=1;i<=n-1;i++)
- {
- a=x0+i*h;
- sum+=2*f(a);
- printf("\n%f\t%f",a,f(a));
- }
- temp=(h/2)*sum;
- printf("\nThe ans is %.6f\n",temp);
- }
- OUTPUT:
- Enter the upper and lower limits1 0
- Enter the no of intervals6
- a f(a)
- 0.166667 0.972973
- 0.333333 0.900000
- 0.500000 0.800000
- 0.666667 0.692308
- 0.833333 0.590164
- The ans is 0.784241
- Press any key to continue
Advertisement
Add Comment
Please, Sign In to add comment